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