public static void main(String[] args) { Thread[] threads = new Thread[2]; threads[0] = new Thread(() -> { for (int i = 0; i < 50; ++i) { System.out.println(“A”); LockSupport.unpark(threads[1]); LockSupport.park(); } });
threads[1] = new Thread(() -> {
for (int i = 0; i < 50; ++i) {
LockSupport.park();
System.out.println("B");
LockSupport.unpark(threads[0]);
}
});
threads[0].start();
threads[1].start();
}
文档信息
- 本文作者:comi
- 本文链接:https://cold-summer.github.io/zzkBlog/fragment/test/
- 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)