public class CountDownLatchTest1 implements Runnable{  
    final AtomicInteger number = new AtomicInteger();  
    volatile boolean bol = false;  
  
    @Override  
    public void run() {  
        System.out.println(number.getAndIncrement());  
        synchronized (this) {  
            try {  
                if (!bol) {  
                    System.out.println(bol);  
                    bol = true;  
                    Thread.sleep(10000);  
                }  
            } catch (InterruptedException e) {  
                e.printStackTrace();  
            }  
            System.out.println("并发数量为" + number.intValue());  
        }  
  
    }  
  
    public static void main(String[] args) {  
        ExecutorService pool = Executors. newCachedThreadPool();  
        CountDownLatchTest1 test = new CountDownLatchTest1();  
        for (int i=0;i<10;i++) {  
            pool.execute(test);  
        }  
    }  
}  

 

相关文章:

  • 2022-12-23
  • 2022-03-03
  • 2021-04-13
  • 2021-11-14
  • 2022-12-23
  • 2021-08-26
  • 2021-07-23
  • 2022-02-14
猜你喜欢
  • 2022-12-23
  • 2021-11-20
  • 2021-06-19
  • 2021-05-29
  • 2021-07-31
  • 2021-08-30
相关资源
相似解决方案