Skip to content

Instantly share code, notes, and snippets.

@andyHa
Created February 2, 2015 13:52
Show Gist options
  • Save andyHa/77f7be2ce87ae06ca03f to your computer and use it in GitHub Desktop.
Save andyHa/77f7be2ce87ae06ca03f to your computer and use it in GitHub Desktop.
Async Demo
Watch w = Watch.start();
int msgs = 10_000_000;
AtomicInteger received = new AtomicInteger();
for (int i = 0; i < msgs; i++) {
Async.defaultExecutor().start(() -> {
Async.defaultExecutor().start(() -> {
int numReceived = received.incrementAndGet();
if (numReceived % 500_000 == 0) {
System.out.println(numReceived + " " + w.duration());
}
}).execute();
}).execute();
}
while (received.get() < msgs) {
Wait.millis(100);
}
System.out.println(w.duration());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment