public interface ReRunnable
extends Runnable
ReRunnable interface should be implemented by any class
whose instances are intended to be executed (and re-executed) by a
DynamicThread dispatched by DynamicThreadPool. The class must define
two parameterless methods:
run()
reset()
Being active simply means that a thread has been started and has not yet been stopped.
Use the DynamicThread.getRunCount() method to obtain the total number of times the run() method has been started.
Just like Runnable, ReRunnable provides the
means for a class to be active while not subclassing Thread,
but it is also designed specifically for use with the DynamicThread class
to reduce processor overhead by reducing/eliminating the number of Thread
and DynamicThread re-creations, which is intended to lead to greater
scalability in high-volume scenarios.
| Modifier and Type | Method and Description |
|---|---|
void |
reset()
Code in this method should reset internal variables, re-instantiate
objects, etc., to their original default values in preparation for run() to
be started again.
|
void |
run()
The same as java.lang.Runnable.run(), except that this code may also be
restarted again after completion (or throwing an uncaught exception).
|
void reset()
After the run() method is completed, reset() is called in order to prepare the current thread so that DynamicThreadPool.dispatch() can dispatch it again as if it were a newly constructed thread.
The DynamicThreadPool class will continue to reset a DynamicThread's ReRunnable object until "maximum dispatches per thread" is exceeded, before destroying the thread.
Do not think of this in terms of a post-run() clean-up method because it isn't called after the final dispatched run. Think of it in terms of being a pre-re-run() re-initialization method. This method is called one less number of times than run(), thus if run() was started 9 times before thread termination, reset() would have been called exactly 8 times throughout.
void run()
run in interface Runnable