Package wt.util
Class WTThread
java.lang.Object
java.lang.Thread
wt.util.WTThread
- All Implemented Interfaces:
Runnable
A thread that is associated with a
WTContext and supports property
change events. This thread class is a Java Bean with bound properties for providing
feedback from the actions taking place within the thread. It also supports two forms of
cancellation, simple local thread interrupt and remote activity cancellation.
This class contains the usual constructors for thread objects, but ThreadGroup
arguments have been replaced with Component arguments. The WTContext
associated with the given Component is used to determine the thread group of the
new thread.
For convenience, an additional start method is provided that allows the calling
thread to wait until the WTThread calls ready. This simplifies the
common task of synchronizing the new thread's access to volatile state that could be affected
if the calling thread is allowed to continue.
Supported API: true
Extendable: true
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionWTThread()Construct a newWTThreadobject.Construct a newWTThreadobject.Construct a newWTThreadobject with the targetRunnable.Construct a newWTThreadobject with the targetRunnableand given name.Construct a newWTThreadobject with the given name.Construct a newWTThreadobject with the targetRunnable.Construct a newWTThreadobject with the targetRunnableand given name.Construct a newWTThreadobject with the given name.WTThread(ThreadGroup thread_group) Construct a newWTThreadobject.WTThread(ThreadGroup thread_group, Runnable target) Construct a newWTThreadobject with the targetRunnable.WTThread(ThreadGroup thread_group, Runnable target, String name) Construct a newWTThreadobject with the targetRunnableand given name.WTThread(ThreadGroup thread_group, String name) Construct a newWTThreadobject with the given name. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a PropertyChangeListener to the listener list.voidcancel()Cancel (interrupt) current server-side processing being performed by this thread.static voidcurrentProgressCount(int progress_count) Set the progress count for the current thread.static voidcurrentProgressPercent(int progress_percent) Set the percentage complete for the current thread.static voidcurrentStatus(String status) Set the status message for the current thread.protected voidfirePropertyChange(String property_name, int old_value, int new_value) Report a bound property update to any registered listeners.protected voidfirePropertyChange(String property_name, Object old_value, Object new_value) Report a bound property update to any registered listeners.intGet the propress count.intGet the percentage complete.Get the status message.Get the state property.voidInterrupt this thread.booleanCheck if this thread has been interrupted.voidready()Notify parent thread that this thread is now ready for it to continue.voidRemove a PropertyChangeListener from the listener list.voidrun()Run method.voidsetInterruptHandler(Runnable interrupt_handler) Set an interrupt handler for this thread.voidsetProgressCount(int progress_count) Set the progress count.voidsetProgressPercent(int progress_percent) Set the percentage complete.voidSet the status message.booleanstart(boolean wait) Start this thread and optionally wait until the thread signals the caller to continue.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupted, isAlive, isDaemon, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Constructor Details
-
WTThread
public WTThread()Construct a newWTThreadobject. The new thread becomes a member of the thread group associated with the currentWTContextobject.
Supported API: true- See Also:
-
WTThread
Construct a newWTThreadobject with the targetRunnable. The new thread becomes a member of the thread group associated with the currentWTContextobject.
Supported API: true- Parameters:
target- the targetRunnable- See Also:
-
WTThread
Construct a newWTThreadobject with the targetRunnableand given name. The new thread becomes a member of the thread group associated with the currentWTContextobject.
Supported API: true- Parameters:
target- the target Runnablename- the thread name- See Also:
-
WTThread
Construct a newWTThreadobject with the given name. The new thread becomes a member of the thread group associated with the currentWTContextobject.
Supported API: true- Parameters:
name- the thread name- See Also:
-
WTThread
Construct a newWTThreadobject. The new thread becomes a member of the thread group associated with the givenComponentobject.
Supported API: true- Parameters:
component- the component that determines thread group.- See Also:
-
WTThread
Construct a newWTThreadobject with the targetRunnable. The new thread becomes a member of the thread group associated with the givenComponentobject.
Supported API: true- Parameters:
component- theComponentthat determines thread group.target- the targetRunnable- See Also:
-
WTThread
Construct a newWTThreadobject with the targetRunnableand given name. The new thread becomes a member of the thread group associated with the givenComponentobject.
Supported API: true- Parameters:
component- theComponentthat determines thread group.target- the targetRunnablename- the thread name- See Also:
-
WTThread
Construct a newWTThreadobject with the given name. The new thread becomes a member of the thread group associated with the givenComponentobject.
Supported API: true- Parameters:
component- theComponentthat determines thread group.name- the thread name- See Also:
-
WTThread
Construct a newWTThreadobject. The new thread becomes a member of the passedThreadGroup
Supported API: true- Parameters:
thread_group- theThreadGroupthat this thread is to be part of- See Also:
-
WTThread
Construct a newWTThreadobject with the targetRunnable. The new thread becomes a member of the passedThreadGroupComponentobject.
Supported API: true- Parameters:
thread_group- theThreadGroupthat this thread is to be part oftarget- the targetRunnable- See Also:
-
WTThread
Construct a newWTThreadobject with the targetRunnableand given name. The new thread becomes a member of the passedThreadGroup
Supported API: true- Parameters:
thread_group- theThreadGroupthat this thread is to be part oftarget- the targetRunnablename- the thread name- See Also:
-
WTThread
Construct a newWTThreadobject with the given name. The new thread becomes a member of the passedThreadGroup
Supported API: true- Parameters:
thread_group- theThreadGroupthat this thread is to be part ofname- the thread name- See Also:
-
-
Method Details
-
start
public boolean start(boolean wait) Start this thread and optionally wait until the thread signals the caller to continue. Ifwaitis true, the calling thread waits until the new thread callsready. This gives the new thread an opportunity to access any volatile state before proceeding. This method returns a boolean value to indicate whether the thread was started successfully or the caller was interrupted while waiting.
Supported API: true- Parameters:
wait- calling thread should wait until this thread signals ready- Returns:
- true if thread started successfully, false if waiting was interrupted
-
ready
public void ready()Notify parent thread that this thread is now ready for it to continue.
Supported API: true -
run
public void run()Run method. This method overrides the default run method to fire property change events for the state property.
Supported API: true -
addPropertyChangeListener
Add a PropertyChangeListener to the listener list.
Supported API: true- Parameters:
listener- thePropertyChangeListenerto be added
-
removePropertyChangeListener
Remove a PropertyChangeListener from the listener list.
Supported API: true- Parameters:
listener- thePropertyChangeListenerto be removed
-
firePropertyChange
Report a bound property update to any registered listeners. No event is fired if old and new are equal and non-null.
Supported API: true- Parameters:
property_name- the programmatic name of the property that was changedold_value- the old value of the propertynew_value- the new value of the property
-
firePropertyChange
Report a bound property update to any registered listeners. No event is fired if old and new are equal and non-null.
Supported API: true- Parameters:
property_name- the programmatic name of the property that was changedold_value- the old value of the propertynew_value- the new value of the property
-
getWtThreadState
Get the state property.
Supported API: true- Returns:
- the state property
-
setStatus
Set the status message.
Supported API: true- Parameters:
status- the status message string
-
getStatus
Get the status message.
Supported API: true- Returns:
- the status message string
-
setProgressPercent
public void setProgressPercent(int progress_percent) Set the percentage complete.
Supported API: true- Parameters:
progress_percent- percentage complete as an integer
-
getProgressPercent
public int getProgressPercent()Get the percentage complete.
Supported API: true- Returns:
- percentage complete as an integer
-
setProgressCount
public void setProgressCount(int progress_count) Set the progress count.
Supported API: true- Parameters:
progress_count- progress count as an integer
-
getProgressCount
public int getProgressCount()Get the propress count.
Supported API: true- Returns:
- progress count as an integer
-
currentStatus
Set the status message for the current thread. Ignored if the current thread is not an instance ofWTThread.
Supported API: true- Parameters:
status- the status message string
-
currentProgressPercent
public static void currentProgressPercent(int progress_percent) Set the percentage complete for the current thread. Ignored if the current thread is not an instance ofWTThread.
Supported API: true- Parameters:
progress_percent- percentage complete as an integer
-
currentProgressCount
public static void currentProgressCount(int progress_count) Set the progress count for the current thread. Ignored if the current thread is not an instance ofWTThread.
Supported API: true- Parameters:
progress_count- percentage complete as an integer
-
setInterruptHandler
Set an interrupt handler for this thread. An interrupt handler is run when this thread is interrupted. It can be used to perform cleanup associated with interrupting this thread, such as interrupting of a remote thread in a server.
Supported API: true -
interrupt
public void interrupt()Interrupt this thread. If an interrupt handler has been set, it will be run.
Supported API: true -
isInterrupted
public boolean isInterrupted()Check if this thread has been interrupted. If thread interrupt is not supported (Netscape Communicator 4.0.4), this method will still returntruethe first time called after theinterruptmethod has been invoked.
Supported API: true- Overrides:
isInterruptedin classThread- Returns:
trueif this thread has been interrupted.
-
cancel
public void cancel()Cancel (interrupt) current server-side processing being performed by this thread. The local thread is not interrupted. Instead, the server-side operation is interrupted and should return an exception to the local thread.This method runs the thread's interrupt handler if it has been set. The interrupt handler is run in the same thread group as this thread.
Supported API: true
-