Java基础学习:多线程26(信号灯法)
-
信号灯法
-
并发协作模型:生产者/消费者模型:-->信号灯法;
-
-
-
代码案例:
/**
* 测试生产者消费者问题2:信号灯法,标志位解决
*/
public class TestPC2 {
public static void main(String[] args) {
TV tv=new TV();
new Player(tv).start();
new Watcher(tv).start();
}
}
//生产者:演员
class Player extends Thread{
TV tv;
public Player(TV tv){
this.tv=tv;
}