com.avian.birds.philos
Class Phil1

java.lang.Object
  extended by javax.swing.SwingWorker<java.lang.String,java.lang.String>
      extended by com.avian.birds.basebirds.AbstractBasicBird
          extended by com.avian.birds.basebirds.StdBird
              extended by com.avian.birds.philos.Phil1
All Implemented Interfaces:
java.lang.Runnable, java.util.concurrent.Future<java.lang.String>, java.util.concurrent.RunnableFuture<java.lang.String>

public class Phil1
extends StdBird

A type of StdBird that is good at philosophizing but not so good at chatting. He shares forks with the philosophers seated at his immediate left and right. He tries to pick up a fork (left or right) and then tries to get the other one. Rules: He can only eat when he has both forks. When he has both forks, he eats for a random length of time and then puts down both forks. When he has one fork, he tries 3 times to pick up the other fork after waiting for random intervals between each attempt. If he cannot get the other fork after 3 tries, he puts down the fork that he was holding and then waits for a random length of time before trying again.


Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.SwingWorker
javax.swing.SwingWorker.StateValue
 
Field Summary
 
Fields inherited from class com.avian.birds.basebirds.StdBird
foodFromTree, healthStatus, jbRefStart, jlRefLastAte, jtaRefHistory, jtfRefHealth, mts, myTupleTree, nts, sampleXmv, startButtonText
 
Fields inherited from class com.avian.birds.basebirds.AbstractBasicBird
bhf, bif, birdDesc, birdHistory, birdName, bof, eatsFood, hatchTime, historyFileName, inputFileName, lastAte, levelOfInfo, lifeTime, napLength, outputFileName, stamina, stopNow, storesFood
 
Constructor Summary
Phil1()
           
 
Method Summary
 void digest()
          Provides the processing functionality for this Bird.
 void eatFood()
          Every Philosopher Bird must eat food to stay alive and this method provides the instructions that this Bird will follow to eat.
 void storeFood()
          Need to put back any forks that we are holding
 
Methods inherited from class com.avian.birds.basebirds.StdBird
checkAge, done, setHealthRef, setHealthStatus, setHistoryAreaRef, setJlRefLastAte, setStartButtonRef, setStartButtonText, setTupleTree
 
Methods inherited from class com.avian.birds.basebirds.AbstractBasicBird
addToBirdHistory, doInBackground, getAuxFood, getBirdDescription, getBirdHistory, getBirdName, getEatsFood, getHatchTime, getHistoryFileName, getInputFileName, getLastAte, getLevelOfInfo, getLifeTime, getNameOfFoodToStore, getNapLength, getOutputFileName, getStamina, isStopNow, setBhf, setBif, setBirdDesc, setBirdHistory, setBirdName, setBof, setEatsFood, setHatchTime, setHistoryFileName, setInputFileName, setLevelOfInfo, setLevelOfInfo, setLifeTime, setNapLength, setOutputFileName, setStamina, setStopNow, setStoresFood
 
Methods inherited from class javax.swing.SwingWorker
addPropertyChangeListener, cancel, execute, firePropertyChange, get, get, getProgress, getPropertyChangeSupport, getState, isCancelled, isDone, process, publish, removePropertyChangeListener, run, setProgress
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Phil1

public Phil1()
Method Detail

eatFood

public void eatFood()
Every Philosopher Bird must eat food to stay alive and this method provides the instructions that this Bird will follow to eat. Because we're just trying to demonstrate deadlock prevention and not a full example, we are going to highjack the storesFood object so that we can specify which forks this philosopher bird will use

Overrides:
eatFood in class StdBird

digest

public void digest()
Provides the processing functionality for this Bird. However, we don't really process anything in the Dining Philosophers problem so, we are just going to delay and then return

Overrides:
digest in class StdBird

storeFood

public void storeFood()
Need to put back any forks that we are holding

Overrides:
storeFood in class StdBird