public Sample[] testBarrier(Runnable action, int threadNumber, int operations) throws InterruptedException, ExecutionException {
System.out.println("Testing " + action + ", threads " + threadNumber + ", operations " + operations);
LatchBarrier start = new LatchBarrier();
int opsPerThread = operations / threadNumber;
ExecutorService pool = Executors.newFixedThreadPool(threadNumber);
List<WorkThread> workers = new ArrayList<WorkThread>();
List<Future<?>> futures = new ArrayList<Future<?>>();
for(int i = 0; i != threadNumber; ++i) {
WorkThread thread = new WorkThread(start, action, opsPerThread);
futures.add(pool.submit(thread));
workers.add(thread);
}
// TODO cyclic alike barrier
Thread.sleep(10);
long startTime = System.nanoTime();
start.open();
for(int i = 0; i != futures.size(); ++i) {
futures.get(i).get();
}