Examples of LatchBarrier


Examples of org.gridkit.util.concurrent.LatchBarrier

   
    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();
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.