コード例 #1
0
 public void think() {
   print("[Philosopher " + position + "] is thinking");
   try {
     Thread.sleep(rnd.nextInt(maxTimeout));
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
   print("[Philosopher " + position + "] is hungry");
   startWait = System.currentTimeMillis();
 }
コード例 #2
0
 public void eat() {
   waitTime += System.currentTimeMillis() - startWait;
   print("[Philosopher " + position + "] is eating");
   try {
     Thread.sleep(rnd.nextInt(maxTimeout));
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
   eatCount++;
   print("[Philosopher " + position + "] finished eating");
 }