import java.util.concurrent.*;
class SemaphoreEx1{
public static void main(String arg[]){
Semaphore sem = new Semaphore(0);
new TA(sem).start();
new TB(sem).start();
}
}
class TA extends Thread{
Semaphore sem;
public TA(Semaphore s){
sem = s;
}
public void run(){
System.out.println("TA going first");
sem.release();
}
}
class TB extends Thread{
Semaphore sem;
public TB(Semaphore s){
sem = s;
}
public void run(){
try{
sem.acquire();
}
catch(InterruptedException e){
}
System.out.println("TB going second");
}
}
初始化是0,怎么TA能获得信号呢?