Created
May 4, 2014 15:01
-
-
Save evsinev/0b136693ef7549ddc9b5 to your computer and use it in GitHub Desktop.
Testing Flight Recorder
This file contains 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.Random; | |
import java.util.concurrent.atomic.AtomicLong; | |
public class Test { | |
public static void main(String args[]) throws Exception { | |
final AtomicLong accumulator = new AtomicLong(); | |
Runnable add = new Runnable() { | |
Random random = new Random(); | |
@Override | |
public void run() { | |
Thread current = Thread.currentThread(); | |
while (!current.isInterrupted()) { | |
accumulator.addAndGet(random.nextLong()); | |
} | |
} | |
}; | |
Thread t1 = new Thread(add); | |
Thread t2 = new Thread(add); | |
t1.start(); | |
t2.start(); | |
Thread.sleep(5000); | |
t1.interrupt(); | |
t2.interrupt(); | |
t1.join(); | |
t2.join(); | |
System.out.println("atomic = " + accumulator); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment