com.isti.util
Class IstiThread

java.lang.Object
  extended byjava.lang.Thread
      extended bycom.isti.util.IstiThread
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
IstiNotifyThread, MemoryInfoLogger.LoggerRunningThread, MsgViaFileProcessor.MsgFileProcessingThread, SameStatusThread, StreamTransferThread, ThreadLogger.LoggerRunningThread

public class IstiThread
extends java.lang.Thread

Class IstiThread extends a thread to add additional functionality and to ensure the thread is given a name.


Field Summary
static int DEFAULT_TERMINATE_WAIT_TIME
          The default terminate wait time in milliseconds.
protected  boolean terminateFlag
          Flag set true if the thread should be terminated.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
IstiThread(java.lang.Runnable target, java.lang.String name)
          Allocates a new IstiThread object.
IstiThread(java.lang.String name)
          Allocates a new IstiThread object.
IstiThread(java.lang.ThreadGroup group, java.lang.Runnable target, java.lang.String name)
          Allocates a new IstiThread object so that it has target as its run object, has the specified name as its name, and belongs to the thread group referred to by group.
IstiThread(java.lang.ThreadGroup group, java.lang.String name)
          Allocates a new IstiThread object.
 
Method Summary
 void clearThreadWaitNotifyFlag()
          Clears the thread-wait notify flag.
 boolean isTerminated()
          Tests if this thread is terminated.
protected static int nextThreadNum()
          Returns (and increments) the next thread number for autonumbering anonymous threads.
 void notifyThread()
          Performs a thread-notify.
 void start()
          Starts this thread if the thread is not terminated and not already alive.
 void terminate()
          Terminates this thread if the thread is not terminated and alive.
 void terminate(long waitTimeMs)
          Terminates this thread if the thread is not terminated and alive.
 void waitForNotify()
          Performs a thread wait.
 boolean waitForNotify(long waitTimeMs)
          Performs a thread wait, up to the given timeout value.
 void waitForTerminate()
          Waits (up to 100 milliseconds) for the thread to terminate.
 void waitForTerminate(long waitTimeMs)
          Waits (up to 'waitTimeMs' milliseconds) for the thread to terminate.
 boolean wasStarted()
          Determines if the thread was already started.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_TERMINATE_WAIT_TIME

public static int DEFAULT_TERMINATE_WAIT_TIME
The default terminate wait time in milliseconds.


terminateFlag

protected boolean terminateFlag
Flag set true if the thread should be terminated.

Constructor Detail

IstiThread

public IstiThread(java.lang.Runnable target,
                  java.lang.String name)
Allocates a new IstiThread object. This constructor has the same effect as IstiThread(null, target, name).

Parameters:
target - the object whose run method is called.
name - the name of the new thread.

IstiThread

public IstiThread(java.lang.String name)
Allocates a new IstiThread object. This constructor has the same effect as IstiThread(null, null, name).

Parameters:
name - the name of the new thread.

IstiThread

public IstiThread(java.lang.ThreadGroup group,
                  java.lang.Runnable target,
                  java.lang.String name)
Allocates a new IstiThread object so that it has target as its run object, has the specified name as its name, and belongs to the thread group referred to by group.

If group is null, the group is set to be the same ThreadGroup as the thread that is creating the new thread.

If there is a security manager, its checkAccess method is called with the ThreadGroup as its argument. This may result in a SecurityException.

If the target argument is not null, the run method of the target is called when this thread is started. If the target argument is null, this thread's run method is called when this thread is started.

The priority of the newly created thread is normally set equal to the priority of the thread creating it, that is, the currently running thread. If the thread is created on the event dispatch thread the priority of the newly created thread is set to the normal priority. The method setPriority may be used to change the priority to a new value.

The newly created thread is initially marked as being a daemon thread if and only if the thread creating it is currently marked as a daemon thread. The method setDaemon may be used to change whether or not a thread is a daemon.

Parameters:
group - the thread group.
target - the object whose run method is called.
name - the name of the new thread.
Throws:
java.lang.SecurityException - if the current thread cannot create a thread in the specified thread group.

IstiThread

public IstiThread(java.lang.ThreadGroup group,
                  java.lang.String name)
Allocates a new IstiThread object. This constructor has the same effect as IstiThread(group, null, name)

Parameters:
group - the thread group.
name - the name of the new thread.
Throws:
java.lang.SecurityException - if the current thread cannot create a thread in the specified thread group.
Method Detail

nextThreadNum

protected static int nextThreadNum()
Returns (and increments) the next thread number for autonumbering anonymous threads.

Returns:
the next thread number.

start

public void start()
Starts this thread if the thread is not terminated and not already alive.

See Also:
wasStarted

terminate

public void terminate()
Terminates this thread if the thread is not terminated and alive.


terminate

public void terminate(long waitTimeMs)
Terminates this thread if the thread is not terminated and alive.

Parameters:
waitTimeMs - the maximum number of milliseconds to wait for the thread to terminate, or 0 to wait indefinitely.

isTerminated

public boolean isTerminated()
Tests if this thread is terminated.

Returns:
true if this thread is terminated; false otherwise.

waitForNotify

public void waitForNotify()
Performs a thread wait. If a notify has occurred since the last call to 'waitForNotify()' or 'clearThreadWaitNotifyFlag()' then this method will return immediately.


waitForNotify

public boolean waitForNotify(long waitTimeMs)
Performs a thread wait, up to the given timeout value. If a notify has occurred since the last call to 'waitForNotify()' or 'clearThreadWaitNotifyFlag()' then this method will return immediately.

Parameters:
waitTimeMs - the maximum number of milliseconds to wait for the thread-notify, or 0 to wait indefinitely.
Returns:
true if the wait-timeout value was reached; false if a thread-notify, thread-interrupt or thread-terminate occurred.

notifyThread

public void notifyThread()
Performs a thread-notify. This will "wake up" the 'waitForNotify()' method.


clearThreadWaitNotifyFlag

public void clearThreadWaitNotifyFlag()
Clears the thread-wait notify flag. This will clear any previous "notifies" set via the 'notifyThread()' method.


wasStarted

public boolean wasStarted()
Determines if the thread was already started.

Returns:
true if the thread was already started, false otherwise.

waitForTerminate

public void waitForTerminate()
Waits (up to 100 milliseconds) for the thread to terminate.


waitForTerminate

public void waitForTerminate(long waitTimeMs)
Waits (up to 'waitTimeMs' milliseconds) for the thread to terminate.

Parameters:
waitTimeMs - the maximum number of milliseconds to wait for the thread to terminate, or 0 to wait indefinitely.