All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.viaoa.concurrent.OAConcurrent Maven / Gradle / Ivy

package com.viaoa.concurrent;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Allows multiple runnables to all start and run at the same time, and waits for them to all complete 
 * before returning.
 * @author vvia
 *
 */
public class OAConcurrent {
    private static Logger LOG = Logger.getLogger(OAConcurrent.class.getName());
    
    private CountDownLatch countDownLatch;
    private CyclicBarrier barrier;
    private Runnable[] runnables;
    
    public OAConcurrent(Runnable[] runnables) {
        this.runnables = runnables;
    }
    
    public void run() throws Exception {
        int max = (runnables == null) ? 0 : runnables.length;
        if (max == 0) return;
        
        countDownLatch = new CountDownLatch(max);
        barrier = new CyclicBarrier(max);
        
        for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy