CyclicBarrier

package com.famous.thread.CyclicBarrier;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class CyclicBarrierTest {

	public static void main(String[] args) {
		final CyclicBarrier cyclicBarrier = new CyclicBarrier(3);
		ExecutorService service = Executors.newCachedThreadPool();

		for (int i = 0; i <= 2; i++) {
			service.execute(new Runnable() {

				@Override
				public void run() {
					System.err.println("begin");
					try {
						cyclicBarrier.await();
					} catch (Exception e) {
						e.printStackTrace();
					}
					System.err.println("end");
				}
			});
		}
		service.shutdown();
	}

}


你可能感兴趣的:(CyclicBarrier)