Skip to content

Instantly share code, notes, and snippets.

@stepancheg
Created October 26, 2016 08:52
Show Gist options
  • Save stepancheg/2f3236cb5428f215eb2d92e0fafed4f2 to your computer and use it in GitHub Desktop.
Save stepancheg/2f3236cb5428f215eb2d92e0fafed4f2 to your computer and use it in GitHub Desktop.
package org.asynchttpclient.future;
import java.util.ArrayList;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/**
* @author Stepan Koltsov
*/
public class Benchmark {
public static void main(String[] args) throws Exception {
for (;;) {
long start = System.currentTimeMillis();
ArrayList<AbstractListenableFuture> futures = new ArrayList<>();
for (int i = 0; i < 100; ++i) {
Thread thread = new Thread(() -> {
for (int j = 0; j < 100_000; ++j) {
AbstractListenableFuture future = newFuture();
future.addListener(() -> {
}, null);
futures.add(future);
}
});
thread.start();
thread.join();
for (AbstractListenableFuture future : futures) {
future.runListeners();
}
}
System.out.println(System.currentTimeMillis() - start);
}
}
private static AbstractListenableFuture newFuture() {
return new AbstractListenableFuture() {
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return false;
}
@Override
public boolean isCancelled() {
return false;
}
@Override
public boolean isDone() {
return false;
}
@Override
public Object get() throws InterruptedException, ExecutionException {
return null;
}
@Override
public Object get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
return null;
}
@Override
public void done() {
}
@Override
public void abort(Throwable t) {
}
@Override
public void touch() {
}
@Override
public CompletableFuture toCompletableFuture() {
return null;
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment