chopstick.java

来自「北大Java 语言程序设计 ppt课件及源码」· Java 代码 · 共 24 行

JAVA
24
字号
/* * This class requires no changes from the 1.0 version.  * It's kept here so the rest of the example can compile. */import java.awt.*;public class Chopstick {    Philosopher owner = null;    public synchronized void release(Philosopher phil) {        if (phil == owner)            owner = null;        notify();    }    public synchronized void grab(Philosopher phil)					throws InterruptedException {        while (owner != null)            wait();        owner = phil;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?