📄 chopstick.java
字号:
/* * This class requires no changes from the 1.0 version. * It's kept here so the rest of the example can compile. */public class Chopstick { Thread holder = null; public synchronized void grab() throws InterruptedException { while (holder != null) wait(); holder = Thread.currentThread(); } public synchronized void release() { holder = null; notify(); } public synchronized void releaseIfMine() { if (holder == Thread.currentThread()) holder = null; notify(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -