1 26 27 package net.sourceforge.groboutils.codecoverage.v2.compiler.testcode; 28 29 30 31 38 public class Synchronized2 implements Runnable 39 { 40 int j = 0; 41 public static void main( String [] args ) throws Exception 42 { 43 Synchronized2 s2 = new Synchronized2(); 44 Thread t1 = new Thread ( s2 ); 45 Thread t2 = new Thread ( s2 ); 46 t1.start(); 47 t2.start(); 48 49 t1.join(); 50 t2.join(); 51 if (s2.j == 20) 52 { 53 Passed.passed( "Synchronized2" ); 54 } 55 } 56 57 58 public void run() 59 { 60 for (int i = 0; i < 10; ++i) 61 { 62 synchronized( this ) 63 { 64 ++j; 65 } 66 try 67 { 68 Thread.sleep( 100 ); 69 } 70 catch (InterruptedException ie) 71 { 72 return; 73 } 74 } 75 } 76 77 } 78 79 | Popular Tags |