|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Thread
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()
|
|
Thread(Runnable target)
Allocates a new Thread object. |
|
Thread(Runnable target,
java.lang.String name)
Allocates a new Thread object. |
|
Thread(java.lang.String name)
Allocates a new Thread object. |
|
Thread(ThreadGroup group,
Runnable target)
Allocates a new Thread object. |
|
Thread(ThreadGroup group,
Runnable target,
java.lang.String name)
Allocates a new Thread object so that it has
target as its run object, has the specified
name as its name, and belongs to the thread group
referred to by group .
|
|
Thread(ThreadGroup group,
Runnable target,
java.lang.String name,
long stackSize)
Allocates a new Thread object so that it has
target as its run object, has the specified
name as its name, belongs to the thread group referred to
by group , and has the specified stack size.
|
|
Thread(ThreadGroup group,
java.lang.String name)
Allocates a new Thread object. |
Method Summary | |
static Thread |
currentThread()
Returns a reference to the currently executing thread object. |
java.lang.String |
getName()
Returns this thread's name. |
int |
getPriority()
Returns this thread's priority. |
ThreadGroup |
getThreadGroup()
Returns the thread group to which this thread belongs. |
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 |
setName(java.lang.String name)
Changes the name of this thread to be equal to the argument name .
|
void |
setPriority(int newPriority)
Changes the priority of this thread. |
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.
|
java.lang.String |
toString()
Returns a string representation of this thread, including the thread's name, priority, and thread group. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int MIN_PRIORITY
public static final int NORM_PRIORITY
public static final int MAX_PRIORITY
Constructor Detail |
public Thread()
public Thread(Runnable target)
Thread
object. This constructor has
the same effect as Thread(null, target,
gname)
, where gname is
a newly generated name. Automatically generated names are of the
form "Thread-"+
n, where n is an integer.
target
- the object whose run
method is called.Thread(java.lang.ThreadGroup,
java.lang.Runnable, java.lang.String)
public Thread(ThreadGroup group, Runnable target)
Thread
object. This constructor has
the same effect as Thread(group, target,
gname)
, where gname is
a newly generated name. Automatically generated names are of the
form "Thread-"+
n, where n is an integer.
group
- the thread group.target
- the object whose run
method is called.
SecurityException
- if the current thread cannot create a
thread in the specified thread group.Thread(java.lang.ThreadGroup,
java.lang.Runnable, java.lang.String)
public Thread(java.lang.String name)
Thread
object. This constructor has
the same effect as Thread(null, null, name)
.
name
- the name of the new thread.Thread(java.lang.ThreadGroup,
java.lang.Runnable, java.lang.String)
public Thread(ThreadGroup group, java.lang.String name)
Thread
object. This constructor has
the same effect as Thread(group, null, name)
group
- the thread group.name
- the name of the new thread.
SecurityException
- if the current thread cannot create a
thread in the specified thread group.Thread(java.lang.ThreadGroup,
java.lang.Runnable, java.lang.String)
public Thread(Runnable target, java.lang.String name)
Thread
object. This constructor has
the same effect as Thread(null, target, name)
.
target
- the object whose run
method is called.name
- the name of the new thread.Thread(java.lang.ThreadGroup,
java.lang.Runnable, java.lang.String)
public Thread(ThreadGroup group, Runnable target, java.lang.String name)
Thread
object so that it has
target
as its run object, has the specified
name
as its name, and belongs to the thread group
referred to by group
.
If group
is null
and there is a
security manager, the group is determined by the security manager's
getThreadGroup
method. If group
is
null
and there is not a security manager, or the
security manager's getThreadGroup
method returns
null
, the group is set to be the same ThreadGroup
as the thread that is creating the new thread.
If there is a security manager, its checkAccess
method is called with the ThreadGroup as its argument.
This may result in a SecurityException.
If the target
argument is not null
, the
run
method of the target
is called when
this thread is started. If the target argument is
null
, this thread's run
method is called
when this thread is started.
The priority of the newly created thread is set equal to the
priority of the thread creating it, that is, the currently running
thread. The method setPriority
may be used to
change the priority to a new value.
The newly created thread is initially marked as being a daemon
thread if and only if the thread creating it is currently marked
as a daemon thread. The method setDaemon
may be used
to change whether or not a thread is a daemon.
group
- the thread group.target
- the object whose run
method is called.name
- the name of the new thread.
SecurityException
- if the current thread cannot create a
thread in the specified thread group.Runnable.run()
,
run()
,
java.lang.Thread#setDaemon(boolean)
,
setPriority(int)
,
java.lang.ThreadGroup#checkAccess()
,
SecurityManager.checkAccess(java.lang.Thread)
public Thread(ThreadGroup group, Runnable target, java.lang.String name, long stackSize)
Thread
object so that it has
target
as its run object, has the specified
name
as its name, belongs to the thread group referred to
by group
, and has the specified stack size.
This constructor is identical to Thread(ThreadGroup,Runnable,String)
with the exception of the fact
that it allows the thread stack size to be specified. The stack size
is the approximate number of bytes of address space that the virtual
machine is to allocate for this thread's stack. The effect of the
stackSize parameter, if any, is highly platform dependent.
On some platforms, specifying a higher value for the
stackSize parameter may allow a thread to achieve greater
recursion depth before throwing a StackOverflowError
.
Similarly, specifying a lower value may allow a greater number of
threads to exist concurrently without throwing an an OutOfMemoryError
(or other internal error). The details of
the relationship between the value of the stackSize parameter
and the maximum recursion depth and concurrency level are
platform-dependent. On some platforms, the value of the
stackSize parameter may have no effect whatsoever.
The virtual machine is free to treat the stackSize parameter as a suggestion. If the specified value is unreasonably low for the platform, the virtual machine may instead use some platform-specific minimum value; if the specified value is unreasonably high, the virtual machine may instead use some platform-specific maximum. Likewise, the virtual machine is free to round the specified value up or down as it sees fit (or to ignore it completely).
Specifying a value of zero for the stackSize parameter will cause this constructor to behave exactly like the Thread(ThreadGroup, Runnable, String) constructor.
Due to the platform-dependent nature of the behavior of this constructor, extreme care should be exercised in its use. The thread stack size necessary to perform a given computation will likely vary from one JRE implementation to another. In light of this variation, careful tuning of the stack size parameter may be required, and the tuning may need to be repeated for each JRE implementation on which an application is to run.
Implementation note: Java platform implementers are encouraged to document their implementation's behavior with respect to the stackSize parameter.
group
- the thread group.target
- the object whose run
method is called.name
- the name of the new thread.stackSize
- the desired stack size for the new thread, or
zero to indicate that this parameter is to be ignored.
SecurityException
- if the current thread cannot create a
thread in the specified thread group.Method Detail |
public static Thread currentThread()
public static void sleep(long millis) throws InterruptedException
millis
- the length of time to sleep in milliseconds.
InterruptedException
- if another thread has interrupted
the current thread. The interrupted status of the
current thread is cleared when this exception is thrown.Object.notify()
public void start()
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).
IllegalThreadStateException
- if the thread was already
started.run()
,
java.lang.Thread#stop()
public void run()
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.
run
in interface Runnable
start()
,
java.lang.Thread#stop()
,
Thread(java.lang.ThreadGroup,
java.lang.Runnable, java.lang.String)
,
Runnable.run()
public final void setPriority(int newPriority)
First the checkAccess
method of this thread is called
with no arguments. This may result in throwing a
SecurityException
.
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.
newPriority
- priority to set this thread to
IllegalArgumentException
- If the priority is not in the
range MIN_PRIORITY
to
MAX_PRIORITY
.
SecurityException
- if the current thread cannot modify
this thread.getPriority()
,
java.lang.Thread#checkAccess()
,
getPriority()
,
getThreadGroup()
,
MAX_PRIORITY
,
MIN_PRIORITY
,
ThreadGroup.getMaxPriority()
public final int getPriority()
setPriority(int)
,
setPriority(int)
public final void setName(java.lang.String name)
name
.
First the checkAccess
method of this thread is called
with no arguments. This may result in throwing a
SecurityException
.
name
- the new name for this thread.
SecurityException
- if the current thread cannot modify this
thread.getName()
,
java.lang.Thread#checkAccess()
,
getName()
public final java.lang.String getName()
setName(java.lang.String)
,
setName(java.lang.String)
public final ThreadGroup getThreadGroup()
public java.lang.String toString()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |