Sun SPOT API
Green Release  


com.sun.squawk
Class VMThread

java.lang.Object
  extended by com.sun.squawk.VMThread
All Implemented Interfaces:
com.sun.squawk.pragma.GlobalStaticFields

public final class VMThread
extends Object
implements com.sun.squawk.pragma.GlobalStaticFields

The Squawk implementation of threads.

Author:
Nik Shaylor, Doug Simon

Nested Class Summary
static class VMThread.ExecutionPoint
          An ExecutionPoint instance encapsulates the details of a point of execution including the thread, a frame offset, the method to which the frame pertains and the bytecode index of an instruction in the method.
 
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
VMThread(Thread apiThread)
          Allocates a new VMThread object to support a given API Thread instance.
 
Method Summary
static int activeCount()
          Returns the current number of active threads in the VM.
static VMThread asVMThread(Thread thread)
           
 void clearBreakpoint()
          Clears the object used to report a breakpoint hit.
 void clearStep()
          Removes the object (if any) that is keeping this thread in single stepping mode.
static VMThread currentThread()
          Returns a reference to the currently executing thread object.
 Thread getAPIThread()
           
 int getDebuggerSuspendCount()
          Gets the value of the debugger suspension counter for this thread.
 VMThread.ExecutionPoint getEventExecutionPoint()
          Gets the method and frame context of this thread at which a debugger event occurred.
 int getInternalStatus()
          Gets the combined values for state and queue.
 Isolate getIsolate()
          Gets the isolate of the thread.
 String getName()
          Gets the name of this thread.
 int getPriority()
          Returns this thread's priority.
 Debugger.SingleStep getStep()
          Returns the step info object.
 int getThreadNumber()
          Gets the number of this thread which is only guaranteed to be unique within this thread's isolate.
 void interrupt()
          Interrupts this thread.
 boolean isAlive()
          Tests if this thread is alive.
 boolean isDaemon()
          Gets the daemon state of the thread.
 void join()
          Waits for this thread to die.
static void monitorNotify(Object object, boolean notifyAll)
          Notify an object.
static void monitorWait(Object object, long delta)
          Wait for an object to be notified.
 int resumeForDebugger(boolean forDetach)
          Decreases the suspension count of this thread.
 void setDaemon(boolean value)
          Sets the daemon state of the thread.
 void setName(String name)
          Sets the name of this thread.
 void setPriority(int newPriority)
          Changes the priority of this thread.
 void setStep(Debugger.SingleStep step)
          Sets the object that will put this thread into single stepping mode the next time it is scheduled to run.
static void sleep(long millis)
          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 Java Virtual Machine calls the run method of this thread.
 int suspendForDebugger()
          Increases the suspension count of this thread.
 String toString()
          Returns a string representation of this thread, including a unique number that identifies the thread and the thread's 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.

See Also:
Constant Field Values

NORM_PRIORITY

public static final int NORM_PRIORITY
The default priority that is assigned to a thread.

See Also:
Constant Field Values

MAX_PRIORITY

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

See Also:
Constant Field Values
Constructor Detail

VMThread

public VMThread(Thread apiThread)
Allocates a new VMThread object to support a given API Thread instance.

This constructor should only be called from a java.lang.Thread constructor.

Parameters:
apiThread - the API thread instance supported by this VM thread
Method Detail

currentThread

public static VMThread currentThread()
Returns a reference to the currently executing thread object.

Returns:
the currently executing thread

setDaemon

public void setDaemon(boolean value)
Sets the daemon state of the thread.


isDaemon

public boolean isDaemon()
Gets the daemon state of the thread.


sleep

public static void sleep(long millis)
                  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:
millis - the length of time to sleep in milliseconds.
Throws:
InterruptedException - if another thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.
See Also:
Object.notify()

yield

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


start

public void start()
Causes this thread to begin execution; the Java 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).

Throws:
IllegalThreadStateException - if the thread was already started.
See Also:
Thread.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.

setPriority

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

Parameters:
newPriority - priority to set this thread to
Throws:
IllegalArgumentException - If the priority is not in the range MIN_PRIORITY to MAX_PRIORITY.
See Also:
getPriority(), Thread.getPriority(), Thread.MAX_PRIORITY, Thread.MIN_PRIORITY

getPriority

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

Returns:
this thread's name.
See Also:
setPriority(int), Thread.setPriority(int)

activeCount

public static int activeCount()
Returns the current number of active threads in the VM.

Returns:
the current number of active threads

join

public final void join()
                throws InterruptedException
Waits for this thread to die.

Throws:
InterruptedException - if another thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.

getName

public final String getName()
Gets the name of this thread. If setName(java.lang.String) has never been called for this thread, the return value will be of the from "Thread-" where 'n' is a unique numeric identifier for this thread.

Returns:
thread name in standard format

setName

public final void setName(String name)
Sets the name of this thread.

Parameters:
name - the new name for this thread

toString

public String toString()
Returns a string representation of this thread, including a unique number that identifies the thread and the thread's priority.

Overrides:
toString in class Object
Returns:
a string representation of this thread.

getDebuggerSuspendCount

public final int getDebuggerSuspendCount()
Gets the value of the debugger suspension counter for this thread.

Returns:
the suspension count for this thread

suspendForDebugger

public final int suspendForDebugger()
Increases the suspension count of this thread.

Returns:
the new suspension count for this thread

resumeForDebugger

public final int resumeForDebugger(boolean forDetach)
Decreases the suspension count of this thread.

Parameters:
forDetach - if true, the count is set to 0
Returns:
the new suspension count for this thread

getEventExecutionPoint

public VMThread.ExecutionPoint getEventExecutionPoint()
Gets the method and frame context of this thread at which a debugger event occurred.

Returns:
null if this thread is not currently reporting an event to the debugger subsystem

getInternalStatus

public final int getInternalStatus()
Gets the combined values for state and queue.

Returns:
the queue in the least significant byte, and the state in the next least significant byte.

getStep

public final Debugger.SingleStep getStep()
Returns the step info object.


setStep

public final void setStep(Debugger.SingleStep step)
Sets the object that will put this thread into single stepping mode the next time it is scheduled to run.

Parameters:
step - the details of the requested step

clearStep

public final void clearStep()
Removes the object (if any) that is keeping this thread in single stepping mode.


clearBreakpoint

public void clearBreakpoint()
Clears the object used to report a breakpoint hit.


getIsolate

public Isolate getIsolate()
Gets the isolate of the thread.

Returns:
the isolate

getAPIThread

public Thread getAPIThread()

asVMThread

public static VMThread asVMThread(Thread thread)

getThreadNumber

public final int getThreadNumber()
Gets the number of this thread which is only guaranteed to be unique within this thread's isolate.

Returns:
an integer identifier for this thread

monitorWait

public static void monitorWait(Object object,
                               long delta)
                        throws InterruptedException
Wait for an object to be notified.

Parameters:
object - the object to wait on
delta - the timeout period
Throws:
InterruptedException - if another thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.

monitorNotify

public static void monitorNotify(Object object,
                                 boolean notifyAll)
Notify an object.

Parameters:
object - the object be notified
notifyAll - flag to notify all waiting threads

interrupt

public void interrupt()
Interrupts this thread.

This method does nothing if the current thread is interrupting itself.

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

If none of the previous conditions hold then this thread's interrupt status will be set.


Sun SPOT API
Green Release  


Copyright © 2006 Sun Microsystems, Inc. All Rights Reserved.