public class TestCount {
CountDownLatch count;
/**
* @param args
*/
public static void main(String[] args) {
TestCount tc = new TestCount(2);
Thread th1 = new Thread(new Runnable() {
@Override
public void run() {
tc.getCount().countDown();
if(tc.getCount().getCount() == 0) {
tc.printstr();
}
}
});
th1.start();
Thread th2 = new Thread(new Runnable() {
@Override
public void run() {
tc.getCount().countDown();
if(tc.getCount().getCount() == 0) {
tc.printstr();
}
}
});
th2.start();
}
public TestCount(Integer count) {
this.count = new CountDownLatch(count);
}
public void printstr() {
System.out.println("end");
}
public CountDownLatch getCount() {
return count;
}
public void setCount(CountDownLatch count) {
this.count = count;
}
}