public final class DynamicThread<Target extends Runnable>
extends Thread
Modifier and Type | Field and Description |
---|---|
static String |
VERSION
Version number of this Package (read-only).
|
Constructor and Description |
---|
DynamicThread(DynamicThreadPool pool,
long poolID,
ThreadGroup threadGroup,
Target target,
String threadName,
long stackSize)
Instantiates a new DynamicThread object.
|
Modifier and Type | Method and Description |
---|---|
long |
getDispatchCount()
Returns the number of times this DynamicThread was dispatched.
|
long |
getExceptionCount()
Returns the number of times an uncaught exception was thrown.
|
DynamicThreadPool |
getPool()
Returns the DynamicThreadPool object that instantiated this DynamicThread
object and is responsible for dispatching it.
|
long |
getPoolID()
Returns the DynamicThread object's ID number that was assigned by the
DynamicThreadPool object.
|
String |
getStatus()
Returns the status of the DynamicThread.
|
Target |
getTarget()
Returns the Target object that was instantiated.
|
Thread |
getThread()
Returns the java.lang.Thread superclass object, but only after the thread
has been started.
|
long |
getThreadID()
Returns the Thread object's ID number that was assigned by the JVM.
|
boolean |
isRunning()
Indicates if this run() method is active.
|
boolean |
isTerminating()
Indicates if this DynamicThread is flagged for termination.
|
void |
run()
Don't call this method directly, use start() to begin execution instead.
|
String |
setStatus(String newStatus)
Updates the status of the DynamicThread.
|
void |
start()
Begins thread execution.
|
void |
terminate()
Causes the thread to terminate before re-run, no matter how many re-runs
may be remaining.
|
activeCount, checkAccess, clone, 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, stop, stop, suspend, toString, yield
public static final String VERSION
public DynamicThread(DynamicThreadPool pool, long poolID, ThreadGroup threadGroup, Target target, String threadName, long stackSize)
The target is the Runnable (or ReRunnable) object. If your compiler generates the "type parameter target is not within its bound" error message, the most likely cause is inconsistent use of Runnable and ReRunnable in various declarations -- determine which one is most appropriate for your DynamicThreadPool object and use it consistently.
pool
- The DynamicThreadPool object that created this DynamicThreadthreadGroup
- The thread group that will adopt the new Thread objectthreadName
- The name to assign to the new Thread objecttarget
- The Runnable (or ReRunnable) Class to be instantiated for the
new Thread objectstackSize
- The size of the stack for use by the new Thread objectIllegalAccessException
- if a public constructor (with no
arguments) in/or the target class is not accessibleInstantiationException
- if a public constructor (with no
arguments) in the target class isn't definedpublic long getDispatchCount()
public long getExceptionCount()
public DynamicThreadPool getPool()
public long getPoolID()
public String getStatus()
public Target getTarget()
This is a very important method because it provides access to the Runnable target class that was instantiated by the DynamicThread constructor and specified as the Runnable target when the Thread was instantiated.
Usage example: MyThread myThread = (MyThread)dynamicThread.getTarget();
It is assumed that certain preparations will be made by way of various public methods, etc., prior to starting the thread. For example, threads dispatched for inbound TCP/IP connections would need to have the relevant Socket object, so a typical modifier method "myThread.setSocket(Socket)" would be used before dynamicThread.start().
public Thread getThread()
public long getThreadID()
Essentially, this is the same as calling Thread.getCurrentThread().getId() but with overhead reduced.
This is a convenience method that both simplifies code (to help eliminate calls like "getThread().getId()"), and reduces CPU utilization (because the Thread.getId() method is only called once, with repeat calls merely referencing a cached version of the Thread ID number).
public boolean isRunning()
This is intended for internal use. It will probably always return true.
public boolean isTerminating()
This is intended for internal use. It will probably always return false.
public void run()
The DynamicThread.start() method performs additional pool clean-up when the thread terminates.
run
in interface Runnable
run
in class Thread
IllegalThreadStateException
- if the thread was previously
started (threads can't be re-started)public String setStatus(String newStatus)
public void start()
start
in class Thread
public void terminate()
If the thread is running, then termination will occur after completion.