Package wt.util

Class WTThread

All Implemented Interfaces:
Runnable

public class WTThread extends Thread
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

  • Constructor Details

    • WTThread

      public WTThread()
      Construct a new WTThread object. The new thread becomes a member of the thread group associated with the current WTContext object.

      Supported API: true
      See Also:
    • WTThread

      public WTThread(Runnable target)
      Construct a new WTThread object with the target Runnable. The new thread becomes a member of the thread group associated with the current WTContext object.

      Supported API: true
      Parameters:
      target - the target Runnable
      See Also:
    • WTThread

      public WTThread(Runnable target, String name)
      Construct a new WTThread object with the target Runnable and given name. The new thread becomes a member of the thread group associated with the current WTContext object.

      Supported API: true
      Parameters:
      target - the target Runnable
      name - the thread name
      See Also:
    • WTThread

      public WTThread(String name)
      Construct a new WTThread object with the given name. The new thread becomes a member of the thread group associated with the current WTContext object.

      Supported API: true
      Parameters:
      name - the thread name
      See Also:
    • WTThread

      public WTThread(Component component)
      Construct a new WTThread object. The new thread becomes a member of the thread group associated with the given Component object.

      Supported API: true
      Parameters:
      component - the component that determines thread group.
      See Also:
    • WTThread

      public WTThread(Component component, Runnable target)
      Construct a new WTThread object with the target Runnable. The new thread becomes a member of the thread group associated with the given Component object.

      Supported API: true
      Parameters:
      component - the Component that determines thread group.
      target - the target Runnable
      See Also:
    • WTThread

      public WTThread(Component component, Runnable target, String name)
      Construct a new WTThread object with the target Runnable and given name. The new thread becomes a member of the thread group associated with the given Component object.

      Supported API: true
      Parameters:
      component - the Component that determines thread group.
      target - the target Runnable
      name - the thread name
      See Also:
    • WTThread

      public WTThread(Component component, String name)
      Construct a new WTThread object with the given name. The new thread becomes a member of the thread group associated with the given Component object.

      Supported API: true
      Parameters:
      component - the Component that determines thread group.
      name - the thread name
      See Also:
    • WTThread

      public WTThread(ThreadGroup thread_group)
      Construct a new WTThread object. The new thread becomes a member of the passed ThreadGroup

      Supported API: true
      Parameters:
      thread_group - the ThreadGroup that this thread is to be part of
      See Also:
    • WTThread

      public WTThread(ThreadGroup thread_group, Runnable target)
      Construct a new WTThread object with the target Runnable. The new thread becomes a member of the passed ThreadGroup Component object.

      Supported API: true
      Parameters:
      thread_group - the ThreadGroup that this thread is to be part of
      target - the target Runnable
      See Also:
    • WTThread

      public WTThread(ThreadGroup thread_group, Runnable target, String name)
      Construct a new WTThread object with the target Runnable and given name. The new thread becomes a member of the passed ThreadGroup

      Supported API: true
      Parameters:
      thread_group - the ThreadGroup that this thread is to be part of
      target - the target Runnable
      name - the thread name
      See Also:
    • WTThread

      public WTThread(ThreadGroup thread_group, String name)
      Construct a new WTThread object with the given name. The new thread becomes a member of the passed ThreadGroup

      Supported API: true
      Parameters:
      thread_group - the ThreadGroup that this thread is to be part of
      name - 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. If wait is true, the calling thread waits until the new thread calls ready. 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
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • addPropertyChangeListener

      public void addPropertyChangeListener(PropertyChangeListener listener)
      Add a PropertyChangeListener to the listener list.

      Supported API: true
      Parameters:
      listener - the PropertyChangeListener to be added
    • removePropertyChangeListener

      public void removePropertyChangeListener(PropertyChangeListener listener)
      Remove a PropertyChangeListener from the listener list.

      Supported API: true
      Parameters:
      listener - the PropertyChangeListener to be removed
    • firePropertyChange

      protected void firePropertyChange(String property_name, Object old_value, Object new_value)
      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 changed
      old_value - the old value of the property
      new_value - the new value of the property
    • firePropertyChange

      protected void firePropertyChange(String property_name, int old_value, int new_value)
      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 changed
      old_value - the old value of the property
      new_value - the new value of the property
    • getWtThreadState

      public String getWtThreadState()
      Get the state property.

      Supported API: true
      Returns:
      the state property
    • setStatus

      public void setStatus(String status)
      Set the status message.

      Supported API: true
      Parameters:
      status - the status message string
    • getStatus

      public 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

      public static void currentStatus(String status)
      Set the status message for the current thread. Ignored if the current thread is not an instance of WTThread.

      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 of WTThread.

      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 of WTThread.

      Supported API: true
      Parameters:
      progress_count - percentage complete as an integer
    • setInterruptHandler

      public void setInterruptHandler(Runnable interrupt_handler)
      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
      Overrides:
      interrupt in class Thread
    • 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 return true the first time called after the interrupt method has been invoked.

      Supported API: true
      Overrides:
      isInterrupted in class Thread
      Returns:
      true if 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