import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
/**
* 阻塞栈的特点是后入先出,每次操作都在栈顶
*
* @author zhen.l
*
*/
public class BlockingDequeTest {
public static void main(String[] args) {
BlockingDeque<Integer> blockingDeque = new LinkedBlockingDeque<Integer>(
10);
for (int i = 0; i < 5; i++) {
try {
blockingDeque.putFirst(i);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
for (int i = 0; i < 5; i++) {
System.out.println(blockingDeque.getFirst());
blockingDeque.removeFirst();
}
}
}
多线程 - 阻塞栈blockingDeque
最新推荐文章于 2022-03-10 04:42:15 发布