java.lang
Class Thread

java.lang.Object
  |
  +--java.lang.Thread

public class Thread
extends Object
implements Runnable

A thread is a thread of execution in a program. The Spotless Virtual Machine allows an application to have multiple threads of execution running concurrently.

An execution thread requires its own stack for local variables, method parameters and method frames. In the standard VM, the stack for any given thread will grow as needed (within in the total memory constraints of the VM). This is not an appropriate model for the memory limited environment in which the Spotless VM will run. For this reason, the threads provided by this class have the option for the application to set the stack size of a thread. If the stack overflows, an error message is displayed and the VM terminated.


Field Summary
static int MAX_PRIORITY
          The maximum priority that a thread can have.
static int MIN_PRIORITY
          The minimum priority that a thread can have.
static int NORM_PRIORITY
          The default priority that is assigned to a thread.
 
Constructor Summary
Thread()
          Allocates a new Thread object.
Thread(Runnable target)
          Allocates a new Thread object.
 
Method Summary
static int activeCount()
          Returns the number of threads alive.
static Thread currentThread()
          Returns a reference to the currently executing thread object.
 int getPriority()
          Returns this thread's priority.
 boolean isAlive()
          Tests if this thread is alive.
 void join()
          Waits for this thread to die.
 void run()
          If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.
 void setPriority(int newPriority)
          Changes the priority of this thread.
static void sleep(long msecs)
          Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds.
 void start()
          Causes this thread to begin execution; the Spotless Virtual Machine calls the run method of this thread.
 String toString()
          Returns a string representation of this thread, including the thread's identity (given by Object.hashCode) and priority.
static void yield()
          Causes the currently executing thread object to temporarily pause and allow other threads to execute.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MIN_PRIORITY

public static final int MIN_PRIORITY
The minimum priority that a thread can have.
Since:
JDK1.0

NORM_PRIORITY

public static final int NORM_PRIORITY
The default priority that is assigned to a thread.
Since:
JDK1.0

MAX_PRIORITY

public static final int MAX_PRIORITY
The maximum priority that a thread can have.
Since:
JDK1.0
Constructor Detail

Thread

public Thread(Runnable target)
Allocates a new Thread object.
Parameters:
target - the object whose run method is called.

Thread

public Thread()
Allocates a new Thread object.
Method Detail

activeCount

public static int activeCount()
Returns the number of threads alive.
Returns:
the number of threads alive

currentThread

public static Thread currentThread()
Returns a reference to the currently executing thread object.
Returns:
the currently executing thread.
Since:
JDK1.0

yield

public static void yield()
Causes the currently executing thread object to temporarily pause and allow other threads to execute.
Since:
JDK1.0

start

public void start()
Causes this thread to begin execution; the Spotless Virtual Machine calls the run method of this thread.

The result is that two threads are running concurrently: the current thread (which returns from the call to the start method) and the other thread (which executes its run method).


run

public void run()
If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.

Subclasses of Thread should override this method.

Specified by:
run in interface Runnable
Tags copied from interface: Runnable
See Also:
run()

isAlive

public final boolean isAlive()
Tests if this thread is alive. A thread is alive if it has been started and has not yet died.
Returns:
true if this thread is alive; false otherwise.

join

public final void join()
                throws InterruptedException
Waits for this thread to die. Returns immediately if this is the current thread or this thread has not been started (i.e. isAlive() returns false). NOTE: This should be implemented using Object.wait() instead of Thread.yield(). Our current implementation of wait() does not correctly notify waiting processes.

setPriority

public final void setPriority(int newPriority)
Changes the priority of this thread.

Otherwise, the priority of this thread is set to the smaller of the specified newPriority and the maximum permitted priority of the thread's thread group. The given priority is modified if necessary to lie in the range MIN_PRIORITY to MAX_PRIORITY,


getPriority

public final int getPriority()
Returns this thread's priority.
Returns:
this thread's priority.

sleep

public static final void sleep(long msecs)
                        throws InterruptedException
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:
msecs - the length of time to sleep in milliseconds.

toString

public String toString()
Returns a string representation of this thread, including the thread's identity (given by Object.hashCode) and priority.
Overrides:
toString in class Object
Returns:
a string representation of this thread.
Since:
JDK1.0