Created
February 12, 2014 21:31
-
-
Save antonarhipov/8964958 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.BitSet; | |
import java.util.concurrent.CountDownLatch; | |
public class WordTearingExample { | |
public static void main(String[] args) throws Exception { | |
BitSet bs = new BitSet(); | |
CountDownLatch latch = new CountDownLatch(1); | |
System.out.println("getting ready"); | |
Thread t1 = new Thread(new Runnable() { | |
public void run() { | |
try { | |
latch.await(); | |
Thread.sleep(1000); | |
} catch (Exception ex) { | |
} | |
bs.set(1); | |
System.out.println("thread1 done"); | |
} | |
}); | |
Thread t2 = new Thread(new Runnable() { | |
public void run() { | |
try { | |
latch.await(); | |
Thread.sleep(1000); | |
} catch (Exception e) { | |
} | |
bs.set(2); | |
System.out.println("thread2 done"); | |
} | |
}); | |
t1.start(); | |
t2.start(); | |
latch.countDown(); | |
t1.join(); | |
t2.join(); | |
System.out.println(bs.get(1)); | |
System.out.println(bs.get(2)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment