Java Thread: CountDownLatch 例子

public class CountDownLatchTest {
 
 @Test
 public void ThreadControllTest() throws InterruptedException{
  // Suppose we have total 10 thread waiting to execute
  final int TOTAL_THREAD_NUM = 10;
  
  // Leverage our system that only allow 5 threads are running in the same time.
  final int COUNT_LATCH = 5; 
  
  // The threads control tool that can control how many threads can runnning at same time.
  CountDownLatch countDownLatch = null;
  
  for( int i=0; i

 

你可能感兴趣的:(Java)