CyclicBarrier线程同步工具

package com.entel.research;

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

public class JunitCyclicBarrier
{
	public static void main(String[] args)
	{
		ExecutorService executorService = Executors.newFixedThreadPool(5);
		
		final CyclicBarrier cyclicBarrier = new CyclicBarrier(5);
		
		
		for(int i=0;i<5;i++)
		{
			Runnable runnable = new Runnable()
			{
				@Override
				public void run()
				{
					try
					{
						System.out.println("This is the waiting");
						cyclicBarrier.await();
						
						System.out.println("The End!!!");
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
			};
			executorService.execute(runnable);
		}
		
		executorService.shutdown();
	}
}
运行结果:


你可能感兴趣的:(Android,exception,string,class,工具)