|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Thread | +--Philosopher
A philosopher spends its life by thinking and eating. To be able to eat, he must get both forks, one on his left side and one on his right side. After finishing eating, he releases both forks. He dies after having completed 5 life cycles. In a real example, the loop would be infinite.
Field Summary | |
private Fork |
firstFork
|
private int |
id
|
private Fork |
leftFork
|
static int |
NO_OF_PHILOSOPHERS
|
static int |
NO_OF_STATES
|
static int |
NO_OF_TURNS
|
private DiningPhilosophers |
parent
|
private Fork |
rightFork
|
private Fork |
secondFork
|
private int |
state
|
static int |
STATE_DEAD
|
static int |
STATE_EATING
|
static int |
STATE_RELEASING
|
static int |
STATE_THINKING
|
static int |
STATE_WAITING
|
static char[] |
STATES
|
private int |
timeToEat
|
private int |
timeToThink
|
Fields inherited from class java.lang.Thread |
contextClassLoader,
daemon,
eetop,
group,
inheritedAccessControlContext,
MAX_PRIORITY,
MIN_PRIORITY,
name,
NORM_PRIORITY,
priority,
single_step,
stillborn,
stopThreadPermission,
target,
threadInitNumber,
threadQ,
values |
Constructor Summary | |
Philosopher(DiningPhilosophers parent,
int id,
Fork leftFork,
Fork rightFork,
int timeToThink,
int timeToEat)
Creates a new philosopher, with a unique ID. |
Method Summary | |
private void |
eat()
Suspends the philosopher for a random number of seconds -- simulation of eaiting. |
Fork |
getLeftFork()
Returns the philosopher's left fork. |
Fork |
getRightFork()
Returns the philosopher's right fork. |
int |
getState()
Returns the philosopher's state. |
void |
run()
Periodically thinks and eats. |
private void |
think()
Suspends the philosopher for a random number of seconds -- simulation of thinking. |
Methods inherited from class java.lang.Thread |
|
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
public static final int NO_OF_PHILOSOPHERS
public static final int NO_OF_STATES
public static final int NO_OF_TURNS
public static final int STATE_THINKING
public static final int STATE_WAITING
public static final int STATE_EATING
public static final int STATE_RELEASING
public static final int STATE_DEAD
public static final char[] STATES
private int id
private int state
private Fork leftFork
private Fork rightFork
private Fork firstFork
private Fork secondFork
private int timeToThink
private int timeToEat
private DiningPhilosophers parent
Constructor Detail |
public Philosopher(DiningPhilosophers parent, int id, Fork leftFork, Fork rightFork, int timeToThink, int timeToEat)
Method Detail |
public int getState()
public Fork getLeftFork()
public Fork getRightFork()
private void think()
private void eat()
public void run()
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |