|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectjava.lang.Thread
threadExamples.Producer
public class Producer
Once started, a Producer will unilaterally start producing
numbers (using the increment with which it is
started). As each number is produced, the run()
method attempts to put it in the message box. Hence, this
Producer may be as much as two numbers ahead of the consumer
(the "consumer" is the Thread removing numbers from the message
box), because there may be one number in the message box
waiting to be consumed, and a second number waiting to be put
into the message box.
A Producer will use either a SingleMessageBox
or a BatonMessageBox, but not both, depending
on which constructor was used.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.lang.Thread |
|---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
| Field Summary |
|---|
| Fields inherited from class java.lang.Thread |
|---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
|---|---|
Producer(BatonMessageBox<java.lang.Integer> batonBox,
int increment)
Constructs a Producer that communicates by means of a BatonMessageBox, and produces values that count up by the given increment. |
|
Producer(SingleMessageBox<java.lang.Integer> simpleBox,
int increment)
Constructs a Producer that communicates by means of a SingleMessageBox, and produces values that count up by the given increment. |
|
| Method Summary | |
|---|---|
void |
run()
Continuously counts up (with a random delay) and puts the next number into a message box, if the message box is available (empty). |
| Methods inherited from class java.lang.Thread |
|---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Producer(SingleMessageBox<java.lang.Integer> simpleBox,
int increment)
simpleBox - The box to use for returning results.increment - The amount by which to count.
public Producer(BatonMessageBox<java.lang.Integer> batonBox,
int increment)
batonBox - The box to use for returning results.increment - The amount by which to count.| Method Detail |
|---|
public void run()
run in interface java.lang.Runnablerun in class java.lang.ThreadThread.run()
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||