哲学家用餐问题的疑问?
//筷子
class Chopstick {
private boolean taken;// 是否被拿起
public synchronized void take() {
// ....
}
public synchronized void drop() {
// ...
}
}
// 哲学家
class Philosopher implements Runnable {
private Chopstick leftChopstick; // 左筷子
private Chopstick rightChopstick;// 右筷子
public Philosopher(Chopstick leftChopstick, Chopstick rightChopstick) {
// 初始化筷子及相关的东东
// ...
}
public void run() {
// 拿起左筷子,拿起右筷子
// ...
}
}
/**
* 死锁的哲学家模拟
* @author Administrator
*/
public class DeadlockingDiningPhilosopher {
/**
* @param args
*/
public static void main(String[] args) {
// 五个哲学家,五个筷子,
}
}
在java编程思想中, 有如上筷子和哲学家, 其行为如上所示, 我要看这程序的时候有点疑问, 很有时候也有这个疑问, 取筷子和放筷子是哲学家的行为, 为什么放置到了筷子对象的身上, 在其它的很时候也感觉到对行为该放置到哪里产生疑问? 有人也有此疑问吗?