首页 > 代码库 > connectedSignal 简单使用

connectedSignal 简单使用

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 = "http://www.mamicode.com/+ connectedSignal.getCount());"test1");		Thread t2 = new Thread(my, "test2");		        t1.start();        t2.start();                connectedSignal.await(); // 等待结束        System.out.println(connectedSignal.getCount()); 	}}

 connectedSignal

connectedSignal 简单使用