标签:blog io 使用 ar java for sp div art
import java.util.concurrent.CountDownLatch; public class CountDown { private static CountDownLatch connectedSignal = new CountDownLatch(50); static class MyThread implements Runnable { public void run() { for (int i = 0; i < 25; ++i) { sale(); } } public synchronized void sale() { if (connectedSignal.getCount() > 0) { Thread current = Thread.currentThread(); connectedSignal.countDown(); System.out.println("Thread id" + current.getId() + "value = " + connectedSignal.getCount()); } } } public static void main(String[] args) throws InterruptedException { MyThread my = new MyThread(); Thread t1 = new Thread(my, "test1"); Thread t2 = new Thread(my, "test2"); t1.start(); t2.start(); connectedSignal.await(); // 等待结束 System.out.println(connectedSignal.getCount()); } }
connectedSignal
标签:blog io 使用 ar java for sp div art
原文地址:http://www.cnblogs.com/chengxin1982/p/3996084.html