Constructors Summary |
---|
public Thread()Allocates a new Thread object.
Threads created this way must have overridden their
run() method to actually do anything.
init(null, "Thread-" + nextThreadNum());
|
public Thread(String name)Allocates a new Thread object with the
given name.
Threads created this way must have overridden their
run() method to actually do anything.
init(null, name);
|
public Thread(Runnable target)Allocates a new Thread object with a
specific target object whose run method
is called.
init(target, "Thread-" + nextThreadNum());
|
public Thread(Runnable target, String name)Allocates a new Thread object with the given
target and name.
init(target, name);
|
Methods Summary |
---|
public static native int | activeCount()Returns the current number of active threads in the virtual machine.
|
public static native java.lang.Thread | currentThread()Returns a reference to the currently executing
Thread object.
|
public final java.lang.String | getName()Returns this thread's name. Note that in CLDC the name
of the thread can only be set when creating the thread.
return String.valueOf(name);
|
public final int | getPriority()Returns this thread's priority.
return priority;
|
private void | init(java.lang.Runnable target, java.lang.String name)Initialize a Thread.
Thread parent = currentThread();
this.target = target;
this.name = name.toCharArray();
this.priority = parent.getPriority();
setPriority(priority);
|
private native synchronized void | internalExit()
|
public void | interrupt()Interrupts this thread. In an implementation conforming
to the CLDC Specification, this operation is not
required to cancel or clean up any pending I/O operations
that the thread may be waiting for.
interrupt0();
|
private native void | interrupt0()
|
public final native boolean | isAlive()Tests if this thread is alive. A thread is alive if it has
been started and has not yet died.
|
public final synchronized void | join()Waits for this thread to die.
while (isAlive()) {
wait(1000);
}
|
private static synchronized int | nextThreadNum()
return ++threadInitNumber;
|
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.
if (target != null) {
target.run();
}
|
public final void | setPriority(int newPriority)Changes the priority of this thread.
if (newPriority > MAX_PRIORITY || newPriority < MIN_PRIORITY) {
throw new IllegalArgumentException();
}
setPriority0(priority, newPriority);
priority = newPriority;
|
private native void | setPriority0(int oldPriority, int newPriority)
|
public static native void | sleep(long millis)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.
|
public synchronized 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).
start(this);
|
private static synchronized void | start(java.lang.Thread thread)
thread.start0();
|
private native void | start0()
|
public java.lang.String | toString()Returns a string representation of this thread, including the
thread's name and priority.
return "Thread[" + getName() + "," + getPriority() + "]";
|
public static native void | yield()Causes the currently executing thread object
to temporarily pause and allow other threads to execute.
|