java.lang
Class Thread

java.lang.Object
  extended by java.lang.Thread
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
ActivityBase, Keyboard, LCPResponder, Motor.Regulator, RCXRotationSensor, RCXRotationSensor.Reader, SimpleGPS

public class Thread
extends Object
implements Runnable

A thread of execution (or task). Now handles priorities, daemon threads and interruptions.


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 priority that is assigned to the primordial thread.
 
Constructor Summary
Thread()
           
Thread(Runnable target)
           
Thread(String name)
           
Thread(String name, Runnable target)
           
 
Method Summary
static Thread currentThread()
           
 int getPriority()
           
 void interrupt()
          Set the interrupted flag.
static boolean interrupted()
           
 boolean isAlive()
           
 boolean isDaemon()
          Set the daemon flag.
 boolean isInterrupted()
           
 void join()
          Join not yet implemented
 void join(long timeout)
           
 void run()
          When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.
 void setDaemon(boolean on)
           
 void setPriority(int priority)
          Set the priority of this thread.
static void sleep(long aMilliseconds)
           
 void start()
           
static void yield()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIN_PRIORITY

public static final int MIN_PRIORITY
The minimum priority that a thread can have. The value is 1.

See Also:
Constant Field Values

NORM_PRIORITY

public static final int NORM_PRIORITY
The priority that is assigned to the primordial thread. The value is 5.

See Also:
Constant Field Values

MAX_PRIORITY

public static final int MAX_PRIORITY
The maximum priority that a thread can have. The value is 10.

See Also:
Constant Field Values
Constructor Detail

Thread

public Thread()

Thread

public Thread(String name)

Thread

public Thread(Runnable target)

Thread

public Thread(String name,
              Runnable target)
Method Detail

isAlive

public final boolean isAlive()

run

public void run()
Description copied from interface: Runnable
When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.

Specified by:
run in interface Runnable

start

public final void start()

yield

public static void yield()

sleep

public static void sleep(long aMilliseconds)
                  throws InterruptedException
Throws:
InterruptedException

currentThread

public static Thread currentThread()

getPriority

public final int getPriority()

setPriority

public final void setPriority(int priority)
Set the priority of this thread. Higher number have higher priority. The scheduler will always run the highest priority thread in preference to any others. If more than one thread of that priority exists the scheduler will time-slice them. In order for lower priority threas to run a higher priority thread must cease to be runnable. i.e. it must exit, sleep or wait on a monitor. It is not sufficient to just yield.

Threads inherit the priority of their parent. The primordial thread has priority NORM_PRIORITY.

Parameters:
priority - must be between MIN_PRIORITY and MAX_PRIORITY.

interrupt

public void interrupt()
Set the interrupted flag. If we are asleep we will wake up and an InterruptedException will be thrown.


interrupted

public static boolean interrupted()

isInterrupted

public final boolean isInterrupted()

isDaemon

public final boolean isDaemon()
Set the daemon flag. If a thread is a daemon thread its existence will not prevent a JVM from exiting.


setDaemon

public final void setDaemon(boolean on)

join

public final void join()
                throws InterruptedException
Join not yet implemented

Throws:
InterruptedException

join

public final void join(long timeout)
                throws InterruptedException
Throws:
InterruptedException