Source:
void run() throws Exception { successMeter = metricsRegistry.meter("#Successful Operations"); failureMeter = metricsRegistry.meter("#Unsuccessful Operations"); switch (configuration.getOperationType()) { case ReadLatency: case Mixed: latency = metricsRegistry.timer("Latency"); break; default: break; } reporter.start(configuration.getPrintingInterval(), TimeUnit.SECONDS); long startTime = System.currentTimeMillis(); AtomicLong count = new AtomicLong(0); long i; for ( i = 0; shouldContinue(startTime, i); i++) { ResultHandler<T, Throwable> resultHandler = new ResultHandler<T, Throwable>() { @Override public T apply(T t, Throwable throwable) { successMeter.mark(); concurrencyControlSemaphore.release(); if (t != null) { assert(throwable == null); SyncBenchmark.this.onSuccess(); synchronized (count) { count.incrementAndGet(); count.notify(); } } else { assert(throwable != null); failureMeter.mark(); logger.error("Encountered failure on thread {}" , throwable.getMessage(), Thread.currentThread().getName(), throwable); concurrencyControlSemaphore.release(); SyncBenchmark.this.onError(throwable); synchronized (count) { count.incrementAndGet(); count.notify(); } } return t; } }; concurrencyControlSemaphore.acquire(); final long cnt = i; switch (configuration.getOperationType()) { case ReadLatency: LatencyListener latencyListener = new LatencyListener(resultHandler, latency); latencyListener.context = latency.time(); resultHandler = latencyListener; break; default: break; } final ResultHandler<T, Throwable> finalResultHandler = resultHandler; CompletableFuture futureResult = CompletableFuture.supplyAsync(() -> { try { finalResultHandler.init(); return performWorkload(cnt); } catch (Exception e) { throw propagate(e); } }, executorService); futureResult.handle(resultHandler); } synchronized (count) { while (count.get() < i) { count.wait(); } } long endTime = System.currentTimeMillis(); logger.info("[{}] operations performed in seconds.", configuration.getNumberOfOperations(), (int) ((endTime - startTime) / 1000)); reporter.report(); reporter.close(); }

Target:
void run() throws Exception { successMeter = metricsRegistry.meter("#Successful Operations"); failureMeter = metricsRegistry.meter("#Unsuccessful Operations"); switch (configuration.getOperationType()) { case ReadLatency: case Mixed: latency = metricsRegistry.timer("Latency"); break; default: break; } reporter.start(configuration.getPrintingInterval(), TimeUnit.SECONDS); long startTime = System.currentTimeMillis(); AtomicLong count = new AtomicLong(0); long i; for ( i = 0; shouldContinue(startTime, i); i++) { ResultHandler<T, Throwable> resultHandler = new ResultHandler<T, Throwable>() { @Override public T apply(T t, Throwable throwable) { successMeter.mark(); concurrencyControlSemaphore.release(); if (t != null) { assert(throwable == null); SyncBenchmark.this.onSuccess(); synchronized (count) { count.incrementAndGet(); count.notify(); } } else { assert(throwable != null); failureMeter.mark(); logger.error("Encountered failure on thread {}" , throwable.getMessage(), Thread.currentThread().getName(), throwable); concurrencyControlSemaphore.release(); SyncBenchmark.this.onError(throwable); synchronized (count) { count.incrementAndGet(); count.notify(); } } return t; } }; concurrencyControlSemaphore.acquire(); final long cnt = i; switch (configuration.getOperationType()) { case ReadLatency: LatencyListener<T> latencyListener = new LatencyListener(resultHandler, latency); latencyListener.context = latency.time(); resultHandler = latencyListener; break; default: break; } final ResultHandler<T, Throwable> finalResultHandler = resultHandler; CompletableFuture<T> futureResult = CompletableFuture.supplyAsync(() -> { try { finalResultHandler.init(); return performWorkload(cnt); } catch (Exception e) { throw propagate(e); } }, executorService); futureResult.handle(resultHandler); } synchronized (count) { while (count.get() < i) { count.wait(); } } long endTime = System.currentTimeMillis(); logger.info("[{}] operations performed in seconds.", configuration.getNumberOfOperations(), (int) ((endTime - startTime) / 1000)); reporter.report(); reporter.close(); }