java多线程
java 队列:阻塞队列 、普通队列
阻塞队列 :在队列空,take() 取出数据时 队列阻塞,线程停止
测试:
/**
* 测试多线程 调用队列
* @author liangxinxin
*
*/
public class TestThread {
private static Queue<String> queue = new ConcurrentLinkedQueue<String>();
private BlockingQueue<Object> eggs = new ArrayBlockingQueue<Object>(5); //阻塞队列
@Override
public void run() {
for (int i = 0; i < 10; i++) {
System.out.println("我将挂起10秒!");
queue.poll();
System.out.println("回到主线程,请稍等,刚才主线程挂起可能还没醒过来!");
}
}
public static void main(String[] args) {
SIATest test = new SIATest();
test.start();
}
}

浙公网安备 33010602011771号