1 26 27 package net.sourceforge.groboutils.codecoverage.v2.compiler.testcode; 28 29 30 31 38 public class Synchronized3 implements Runnable 39 { 40 int j = 0; 41 public static void main( String [] args ) throws Exception 42 { 43 Synchronized3 s2 = new Synchronized3(); 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 == 6) 52 { 53 Passed.passed( "Synchronized3" ); 54 } 55 } 56 57 58 public void run() 59 { 60 for (int i = 0; i < 10; ++i) 61 { 62 synchronized( this ) 63 { 64 if (i == 3) 65 { 66 throw new RuntimeException (); 67 } 68 ++j; 69 } 70 try 71 { 72 Thread.sleep( 100 ); 73 } 74 catch (InterruptedException ie) 75 { 76 return; 77 } 78 } 79 } 80 81 } 82 83 | Popular Tags |