As expected, these constants specify the maximum, minimum, and default thread priorities.
The methods defined byThreadare shown in Table 16-17. In early versions of Java,Thread
also included the methodsstop( ),suspend( ), andresume( ). However, as explained in
Chapter 11, these were deprecated because they were inherently unstable. Also deprecated
arecountStackFrames( ), because it callssuspend( ), anddestroy( ), because it can cause deadlock.
Chapter 16: Exploring java.lang 423
Method Description
static int activeCount( ) Returns the number of threads in the group to
which the thread belongs.
final void checkAccess( ) Causes the security manager to verify that the
current thread can access and/or change the
thread on whichcheckAccess( )is called.
static Thread currentThread( ) Returns aThreadobject that encapsulates the
thread that calls this method.
static void dumpStack( ) Displays the call stack for the thread.
static int enumerate(Threadthreads[ ]) Puts copies of allThreadobjects in the current
thread’s group intothreads.The number of threads
is returned.
static Map<Thread, StackTraceElement[ ]>
getAllStackTraces( )
Returns aMapthat contains the stack traces for
all active threads. In the map, each entr y consists
of a key, which is theThreadobject, and its value,
which is an array ofStackTraceElement.
ClassLoader getContextClassLoader( ) Returns the class loader that is used to load
classes and resources for this thread.
static Thread.UncaughtExceptionHandler
getDefaultUncaughtExceptionHandler( )
Returns the default uncaught exception handler.
long getID( ) Returns the ID of the invoking thread.
final String getName( ) Returns the thread’s name.
final int getPriority( ) Returns the thread’s priority setting.
StackTraceElement[ ] getStackTrace( ) Returns an array containing the stack trace for the
invoking thread.
Thread.State getState( ) Returns the invoking thread’s state.
final ThreadGroup getThreadGroup( ) Returns theThreadGroupobject of which the
invoking thread is a member.
Thread.UncaughtExceptionHandler
getUncaughtExceptionHandler( )
Returns the invoking thread’s uncaught exception
handler.
static boolean holdsLock(Objectob) Returnstrueif the invoking thread owns the lock
onob.Returnsfalseother wise.
void interrupt( ) Interrupts the thread.
static boolean interrupted( ) Returnstrueif the currently executing thread has
been scheduled for interruption. Other wise, it
returnsfalse.
TABLE 16-17 The Methods Defined byThread