com.internationalnetwork.lang
Interface ReRunnable

All Superinterfaces:
Runnable

public interface ReRunnable
extends Runnable

The 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()
This method is executed when a thread is activated by DynamicThread.start().

reset()
This method is executed before run() is activated again by the DynamicThread.start() method, and is intended to reset package variables and re-instantiate package objects to default values.

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.


Method Summary
 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).
 

Method Detail

reset

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.

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.


run

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). See the reset() method for full details.

Specified by:
run in interface Runnable