| Method from java.lang.VMThread Detail: |
native int countStackFrames()Deprecated! unsafe - operation
Returns the number of stack frames in this Thread.
Will only be called when when a previous call to suspend() returned true. |
static void create(Thread thread,
long stacksize) {
VMThread vmThread = new VMThread(thread);
vmThread.start(stacksize);
thread.vmThread = vmThread;
}
Creates a native Thread. This is called from the start method of Thread.
The Thread is started. |
static native Thread currentThread()
Return the Thread object associated with the currently executing
thread. |
String getName() {
return thread.name;
}
Gets the name of the thread. Usually this is the name field of the
associated Thread object, but some implementation might choose to
return the name of the underlying platform thread. |
int getPriority() {
return thread.priority;
}
Returns the priority. Usually this is the priority field from the
associated Thread object, but some implementation might choose to
return the priority of the underlying platform thread. |
static boolean holdsLock(Object obj) {
/* Use obj.notify to check if the current thread holds
* the monitor of the object.
* If it doesn't, notify will throw an exception.
*/
try
{
obj.notify();
// okay, current thread holds lock
return true;
}
catch (IllegalMonitorStateException e)
{
// it doesn't hold the lock
return false;
}
}
Checks whether the current thread holds the monitor on a given object.
This allows you to do assert Thread.holdsLock(obj). |
native void interrupt()
|
static native boolean interrupted()
Determine whether the current Thread has been interrupted, and clear
the interrupted status in the process. |
boolean isDaemon() {
return thread.daemon;
}
Returns true if the thread is a daemon thread. Usually this is the
daemon field from the associated Thread object, but some
implementation might choose to return the daemon state of the underlying
platform thread. |
native boolean isInterrupted()
Determine whether this Thread has been interrupted, but leave
the interrupted status alone in the process. |
synchronized void join(long ms,
int ns) throws InterruptedException {
// Round up
ms += (ns != 0) ? 1 : 0;
// Compute end time, but don't overflow
long now = System.currentTimeMillis();
long end = now + ms;
if (end < now)
end = Long.MAX_VALUE;
// A VM is allowed to return from wait() without notify() having been
// called, so we loop to handle possible spurious wakeups.
while(thread.vmThread != null)
{
// We use the VMThread object to wait on, because this is a private
// object, so client code cannot call notify on us.
wait(ms);
if(ms != 0)
{
now = System.currentTimeMillis();
ms = end - now;
if(ms < = 0)
{
break;
}
}
}
}
Wait the specified amount of time for the Thread in question to die.
Note that 1,000,000 nanoseconds == 1 millisecond, but most VMs do
not offer that fine a grain of timing resolution. Besides, there is
no guarantee that this thread can start up immediately when time expires,
because some other thread may be active. So don't expect real-time
performance. |
native void nativeSetPriority(int priority)
Set the priority of the underlying platform thread. |
native void nativeStop(Throwable t)
Asynchronously throw the specified throwable in this Thread. |
native void resume()
Resume this Thread. If the thread is not suspended, this method does
nothing. |
void setName(String name) {
thread.name = name;
}
Set the name of the thread. Usually this sets the name field of the
associated Thread object, but some implementations might choose to
set the name of the underlying platform thread. |
void setPriority(int priority) {
thread.priority = priority;
nativeSetPriority(priority);
}
Set the thread priority field in the associated Thread object and
calls the native method to set the priority of the underlying
platform thread. |
static void sleep(long ms,
int ns) throws InterruptedException {
// Note: JDK treats a zero length sleep is like Thread.yield(),
// without checking the interrupted status of the thread.
// It's unclear if this is a bug in the implementation or the spec.
// See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6213203
if (ms == 0 && ns == 0)
{
if (Thread.interrupted())
throw new InterruptedException();
return;
}
// Compute end time, but don't overflow
long now = System.currentTimeMillis();
long end = now + ms;
if (end < now)
end = Long.MAX_VALUE;
// A VM is allowed to return from wait() without notify() having been
// called, so we loop to handle possible spurious wakeups.
VMThread vt = Thread.currentThread().vmThread;
synchronized (vt)
{
while (true)
{
vt.wait(ms, ns);
now = System.currentTimeMillis();
if (now >= end)
break;
ms = end - now;
ns = 0;
}
}
}
Suspend the current Thread's execution for the specified amount of
time. The Thread will not lose any locks it has during this time. There
are no guarantees which thread will be next to run, but most VMs will
choose the highest priority thread that has been waiting longest.
Note that 1,000,000 nanoseconds == 1 millisecond, but most VMs do
not offer that fine a grain of timing resolution. Besides, there is
no guarantee that this thread can start up immediately when time expires,
because some other thread may be active. So don't expect real-time
performance. |
native void start(long stacksize)
Create a native thread on the underlying platform and start it executing
on the run method of this object. |
void stop(Throwable t) {
// Note: we assume that we own the lock on thread
// (i.e. that Thread.stop() is synchronized)
if(running)
nativeStop(t);
else
thread.stillborn = t;
} Deprecated! unsafe - operation, try not to use
Cause this Thread to stop abnormally and throw the specified exception.
If you stop a Thread that has not yet started, the stop is ignored
(contrary to what the JDK documentation says).
WARNINGThis bypasses Java security, and can throw a checked
exception which the call stack is unprepared to handle. Do not abuse
this power.
This is inherently unsafe, as it can interrupt synchronized blocks and
leave data in bad states.
NOTE stop() should take care not to stop a thread if it is
executing code in this class. |
native void suspend()
Suspend this Thread. It will not come back, ever, unless it is resumed. |
static native void yield()
Yield to another thread. The Thread will not lose any locks it holds
during this time. There are no guarantees which thread will be
next to run, and it could even be this one, but most VMs will choose
the highest priority thread that has been waiting longest. |