|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--DiningPhilosophers
Dining philosophers example. The program uses Java threads and locks provided by the synchronized keyword. Output on console -- text mode application. The program terminates when all philosophers have already eaten and thought 5 times. You can redefine the Philosopher.NO_OF_TURNS constant or rewrite the Philosopher.run() method (replace for(...) with while(true)) to change this behavior.
Field Summary | |
private Fork[] |
forks
|
private int |
noOfLivingPhilosophers
|
private Philosopher[] |
philosophers
|
private int |
timeToEat
|
private int |
timeToThink
|
Constructor Summary | |
DiningPhilosophers()
|
Method Summary | |
private void |
createThreads()
Creates all philosophers. |
void |
decrementCountOfPhilosophers()
Decrements the count of philosophers present in the program. |
private void |
doIt(java.lang.String[] args)
If command line parameters are accepted, creates philosophers, lets them run and waits until they all finish. |
private void |
hello()
Prints out a hello message. |
static void |
main(java.lang.String[] args)
Runs the program. |
private void |
printExplanation()
Prints out an explanation of symbols used during program output. |
void |
printForks()
Prints out a line describing the current state of forks and philosophers. |
private boolean |
setTimes(java.lang.String[] args)
Processes command line parameters. |
private void |
usage()
Prints out a message explaining program's usage. |
private void |
waitForZeroPhilosophers()
Blocks until all philosophers finish their work. |
Methods inherited from class java.lang.Object |
|
Field Detail |
private int noOfLivingPhilosophers
private int timeToThink
private int timeToEat
private Fork[] forks
private Philosopher[] philosophers
Constructor Detail |
public DiningPhilosophers()
Method Detail |
public static void main(java.lang.String[] args)
private void doIt(java.lang.String[] args)
private void hello()
private boolean setTimes(java.lang.String[] args)
private void printExplanation()
private void createThreads()
private void usage()
public void printForks()
public void decrementCountOfPhilosophers()
private void waitForZeroPhilosophers()
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |