marf.util
Class BaseThread

java.lang.Object
  extended by java.lang.Thread
      extended by marf.util.BaseThread
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
FeatureExtractionAggregator.FeatureExtractionThread, GUIThread, Layer, Logger, Neuron, SampleRecorder

public class BaseThread
extends java.lang.Thread

Class BaseThread is customized base class for many of our own threads.

It provides an attempt to maintain an automatic unique TID (thread ID) among all the derivatives and allow setting your own if needed, integrates with ExpandedThreadGroup, and maintains a local reference for the Runnable target if clients need it.

Java 1.5 NOTE: In this Java version they finally managed to provide a method similar to our getTID(), called getId() and this class was created prior that. And the functionality we offer seems to be superior anyway.

$Id: BaseThread.java,v 1.18 2007/12/23 06:29:46 mokhov Exp $

Since:
0.3.0.1
Version:
$Revision: 1.18 $
Author:
Serguei Mokhov
See Also:
ExpandedThreadGroup, Runnable, iTID, getNextTID(), getTID()

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  int iTID
          Our Thread ID.
protected  java.lang.Runnable oTarget
          Local references to the target, in case clients need it.
protected static int siNextTID
          Next TID to be assigned.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
BaseThread()
          Default constructor.
BaseThread(ExpandedThreadGroup poThreadGroup, java.lang.Runnable poTarget)
          Assigns name to the thread and places it to the specified expanded group.
BaseThread(ExpandedThreadGroup poThreadGroup, java.lang.Runnable poTarget, java.lang.String pstrName)
          Assigns name to the thread and places it to the specified expanded group.
BaseThread(ExpandedThreadGroup poThreadGroup, java.lang.String pstrName)
          Assigns name to the thread and places it to the specified expanded group.
BaseThread(int piTID)
          Sets user-specified thread ID and resets the sequencing from it.
BaseThread(java.lang.Runnable poTarget)
          Constructor with Runnable.
BaseThread(java.lang.Runnable poTarget, java.lang.String pstrName)
          Constructor with Runnable and thread name.
BaseThread(java.lang.String pstrName)
          Assigns name to the thread.
BaseThread(java.lang.ThreadGroup poThreadGroup, java.lang.Runnable poTarget, java.lang.String pstrName)
          Constructor with ThreadGroup, Runnable, and thread name.
BaseThread(java.lang.ThreadGroup poThreadGroup, java.lang.String pstrName)
          Assigns name to the thread and places it to the specified group.
 
Method Summary
static java.lang.String getMARFSourceCodeRevision()
          Retrieves class' revision.
static int getNextTID()
          Lets to examine the next TID to be assigned.
 java.lang.Runnable getTarget()
          Retrieves the thread's target.
 int getTID()
          Retrieves our TID.
private  void setTID()
          Sets internal TID and updates next TID on contruction time, so it's private.
 
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, run, 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
 

Field Detail

siNextTID

protected static int siNextTID
Next TID to be assigned. Preserves value across all instances.


iTID

protected int iTID
Our Thread ID.


oTarget

protected java.lang.Runnable oTarget
Local references to the target, in case clients need it.

Constructor Detail

BaseThread

public BaseThread()
Default constructor. Calls Thread's constructor and setTID().


BaseThread

public BaseThread(java.lang.Runnable poTarget)
Constructor with Runnable. Calls Thread's constructor with the Runnable argument and setTID().

Parameters:
poTarget - runnable Thread-like object.

BaseThread

public BaseThread(java.lang.Runnable poTarget,
                  java.lang.String pstrName)
Constructor with Runnable and thread name. Equivalent to this(null, poTarget, pstrName).

Parameters:
poTarget - runnable Thread-like object.
pstrName - name of the thread.

BaseThread

public BaseThread(java.lang.ThreadGroup poThreadGroup,
                  java.lang.Runnable poTarget,
                  java.lang.String pstrName)
Constructor with ThreadGroup, Runnable, and thread name. Equivalent to super(poThreadGroup, poTarget, pstrName), but overridden to call setTID().

Parameters:
poThreadGroup - ThreadGroup to add this thread to
poTarget - runnable Thread-like object.
pstrName - name of the thread.

BaseThread

public BaseThread(java.lang.ThreadGroup poThreadGroup,
                  java.lang.String pstrName)
Assigns name to the thread and places it to the specified group. Equivalent to BaseThread(poThreadGroup, null, pstrName).

Parameters:
poThreadGroup - ThreadGroup to add this thread to
pstrName - A string indicating human-readable thread's name

BaseThread

public BaseThread(java.lang.String pstrName)
Assigns name to the thread. Equivalent to BaseThread(null, null, pstrName).

Parameters:
pstrName - A string indicating human-readable thread's name

BaseThread

public BaseThread(ExpandedThreadGroup poThreadGroup,
                  java.lang.String pstrName)
Assigns name to the thread and places it to the specified expanded group. Calls this(poThreadGroup, null, pstrName), but also keeps a local reference to this thread inside the group.

Parameters:
poThreadGroup - ExpandedThreadGroup to add this thread to
pstrName - A string indicating human-readable thread's name

BaseThread

public BaseThread(ExpandedThreadGroup poThreadGroup,
                  java.lang.Runnable poTarget)
Assigns name to the thread and places it to the specified expanded group. Calls this(poThreadGroup, poTarget, null), but also keeps a local reference to this thread inside the group.

Parameters:
poThreadGroup - ExpandedThreadGroup to add this thread to
poTarget - runnable Thread-like object.

BaseThread

public BaseThread(ExpandedThreadGroup poThreadGroup,
                  java.lang.Runnable poTarget,
                  java.lang.String pstrName)
Assigns name to the thread and places it to the specified expanded group. Does super(poThreadGroup, poTarget, pstrName), but also keeps a local reference to this thread inside the group.

Parameters:
poThreadGroup - ExpandedThreadGroup to add this thread to
poTarget - runnable Thread-like object.
pstrName - A string indicating human-readable thread's name

BaseThread

public BaseThread(int piTID)
Sets user-specified thread ID and resets the sequencing from it.

Parameters:
piTID - starting TID
Method Detail

getTID

public final int getTID()
Retrieves our TID.

Returns:
TID, integer

setTID

private final void setTID()
Sets internal TID and updates next TID on contruction time, so it's private.


getNextTID

public static final int getNextTID()
Lets to examine the next TID to be assigned.

Returns:
next TID, integer

getTarget

public java.lang.Runnable getTarget()
Retrieves the thread's target. Proved to be useful in some cases, e.g. in the GIPSY, needed to know who was actually the target postmortem.

Returns:
Returns the Runnable target set during construction

getMARFSourceCodeRevision

public static java.lang.String getMARFSourceCodeRevision()
Retrieves class' revision.

Returns:
revision string


SourceForge Logo