Skip to content

Instantly share code, notes, and snippets.

@evsinev
Created May 4, 2014 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evsinev/0b136693ef7549ddc9b5 to your computer and use it in GitHub Desktop.
Save evsinev/0b136693ef7549ddc9b5 to your computer and use it in GitHub Desktop.
Testing Flight Recorder
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