com.plumtree.openfoundation.util
Class XPThread

java.lang.Object
  extended bycom.plumtree.openfoundation.util.XPThread

public class XPThread
extends java.lang.Object

A thread of execution in a program. This class is used to create and control a thread, set its priority and get its status.


Constructor Summary
XPThread(IXPRunnable runnable)
          Initializes a new instance of the XPThread class.
 
Method Summary
static void DumpStack()
          Print a stack trace of the current thread.
static XPThread GetCurrentThread()
          Gets the currently running thread.
 java.lang.String GetName()
          Gets the name of this thread.
 XPThreadPriority GetPriority()
          Gets the priority of this thread.
static java.lang.String GetStackTrace()
          Get the current thread's stack trace.
 void Interrupt()
          Interrupts this thread.
 boolean IsAlive()
          Tests if this thread is alive.
 boolean IsBackgroundThread()
          Tests if this thread is a background thread.
 void Join()
          Waits for this thread to die.
 void Join(int milliseconds)
          Waits at most the given milliseconds for this thread to die.
 void Join(int milliseconds, int nanoseconds)
          Waits at most the given milliseconds plus the given nanos nanoseconds for this thread to die.
 void Kill()
          Deprecated. Deprecated in JDK1.4 - behaviour not guaranteed. DO NOT USE IN PRODUCTION CODE!
 void SetBackground(boolean b)
          Marks this thread as either a daemon thread or a user thread.
 void SetName(java.lang.String name)
          Sets the name of this thread.
 void SetPriority(XPThreadPriority priority)
          Changes the priority of this thread.
static void Sleep(int milliSeconds)
          Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds.
 void Start()
          Causes this thread to start being execution; the VM calls the run method of this thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XPThread

public XPThread(IXPRunnable runnable)
Initializes a new instance of the XPThread class.

Parameters:
runnable - object whose run method is called
Throws:
XPIllegalArgumentException - if runnable is null
Method Detail

Start

public void Start()
Causes this thread to start being execution; the VM calls the run method of this thread.


GetCurrentThread

public static XPThread GetCurrentThread()
Gets the currently running thread.

Returns:
the currently running thread.

DumpStack

public static void DumpStack()
Print a stack trace of the current thread. The underlying implementation uses XPException.GetStackTrace(). This method is used for debugging purpose.


GetStackTrace

public static java.lang.String GetStackTrace()
Get the current thread's stack trace. This method is used for debugging purpose.

Returns:
string representation of the stack trace.

SetName

public void SetName(java.lang.String name)
Sets the name of this thread.

Parameters:
name - the name for this thread.

GetName

public java.lang.String GetName()
Gets the name of this thread.

Returns:
the name of this thread.

SetPriority

public void SetPriority(XPThreadPriority priority)
Changes the priority of this thread.

First the checkAccess method of this thread is called with no arguments. This may result in throwing a XPSecurityException.

Otherwise, the priority of this thread is set to the smaller of the specified priority and the maximum permitted priority of the thread's thread group.

Parameters:
priority - priority to set this thread to.

GetPriority

public XPThreadPriority GetPriority()
Gets the priority of this thread. A thread can be assigned any one of the following priority values: Highest AboveNormal Normal BelowNormal Lowest

Returns:
returns the current priority of the thread.

IsAlive

public boolean IsAlive()
Tests if this thread is alive.

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

IsBackgroundThread

public boolean IsBackgroundThread()
Tests if this thread is a background thread.

Returns:
true if this thread is a background thread; false otherwise.

Join

public void Join()
Waits for this thread to die.


Join

public void Join(int milliseconds)
Waits at most the given milliseconds for this thread to die. A timeout of 0 means to wait forever.

Parameters:
milliseconds - the time to wait in milliseconds.

Join

public void Join(int milliseconds,
                 int nanoseconds)
Waits at most the given milliseconds plus the given nanos nanoseconds for this thread to die.

Parameters:
milliseconds - the time to wait in milliseconds.
nanoseconds - 0-999999 additional nanoseconds to wait.

Sleep

public static void Sleep(int milliSeconds)
Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds. The thread does not lose ownership of any monitors.

Parameters:
milliSeconds - the length of time to sleep in milliseconds.
Throws:
XPThreadInterruptedException - if interrupted.

SetBackground

public void SetBackground(boolean b)
Marks this thread as either a daemon thread or a user thread. The Java Virtual Machine exits when the only threads running are all daemon threads.

This method must be called before the thread is started.

This method first calls the checkAccess method of this thread with no arguments. This may result in throwing a SecurityException (in the current thread).

Parameters:
b - true will make this thread background.

Interrupt

public void Interrupt()
Interrupts this thread.

First the checkAccess method of this thread is invoked, which may cause a XPSecurityException to be thrown.

If this thread is blocked in an invocation of the wait(), wait(long), or wait(long, int) methods of the Object class, or of the #join(), #join(long), #join(long, int), #sleep(long), or #sleep(long, int), methods of this class, then its interrupt status will be cleared and it will receive an XPInterruptedException.


Kill

public void Kill()
Deprecated. Deprecated in JDK1.4 - behaviour not guaranteed. DO NOT USE IN PRODUCTION CODE!

Terminate the thread (stop or abort). Recommended only when the thread will not respond to Interrupt(), such as a runaway JNI/native subprocess.



Copyright © 2002, 2003, 2004 Plumtree Software Inc. All Rights Reserved.