/*
同步队列,放入一个元素,如果这个元素没有被消费就阻塞着*/
package 修改文件内容;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.SynchronousQueue;
import javax.swing.plaf.SliderUI;
public class zuseduilie {
public static BlockingQueue<String> que=new SynchronousQueue<String>();
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
new Thread(){
public void run() {
System.out.println("放入第一个数据");
try {
que.put("第1个数据");
System.out.println("放入第2个元素");
que.put("第2个数据");
System.out.println("放入第3个元素");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
}.start();
Thread.sleep(2000);
new Thread(){
public void run() {
try {
System.out.println("消费一个数据"+que.take());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
}.start();
}
}