public class TestBlockQueueMutex {
static BlockingQueue<Integer> bq1 = new LinkedBlockingQueue<Integer>(1);
static BlockingQueue<Integer> bq2 = new LinkedBlockingQueue<Integer>(1);
public static void main(String[] args) {
bq2.offer(1);
new Thread(){
public void run() {
try {
while(true){
bq1.put(1);
System.out.println("1111");
bq2.take();
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
}.start();
new Thread(){
public void run() {
try {
while(true){
bq2.put(1);
System.out.println("2222");
bq1.take();
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
}.start();
}
}
利用阻塞队列进行互斥通知
最新推荐文章于 2022-12-01 21:48:15 发布