Skip to Content
Java in a Nutshell, 5th Edition
book

Java in a Nutshell, 5th Edition

by David Flanagan
March 2005
Intermediate to advanced
1254 pages
104h 21m
English
O'Reilly Media, Inc.
Content preview from Java in a Nutshell, 5th Edition

Name

Thread

Synopsis

This class encapsulates all information about a single thread of control running on the Java interpreter. To create a thread, you must either pass a Runnable object (i.e., an object that implements the Runnable interface by defining a run( ) method) to the Thread constructor or subclass Thread so that it defines its own run( ) method. The run( ) method of the Thread or of the specified Runnable object is the body of the thread. It begins executing when the start( ) method of the Thread object is called. The thread runs until the run( ) method returns. isAlive( ) returns true if a thread has been started, and the run( ) method has not yet exited.

The static methods of this class operate on the currently running thread. currentThread( ) returns the Thread object of the currently running code. sleep( ) makes the current thread stop for a specified amount of time. yield( ) makes the current thread give up control to any other threads of equal priority that are waiting to run. holdsLock( ) tests whether the current thread holds a lock (through a synchronized method or statement) on the specified object; this Java 1.4 method is often useful with an assert statement.

The instance methods may be called by one thread to operate on a different thread. checkAccess( ) checks whether the running thread has permission to modify a Thread object and throws a SecurityException if it does not. join( ) waits for a thread to die. interrupt( ) wakes up a waiting or sleeping ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java in a Nutshell, 8th Edition

Java in a Nutshell, 8th Edition

Benjamin J. Evans, Jason Clark, David Flanagan
Java in a Nutshell, 7th Edition

Java in a Nutshell, 7th Edition

Benjamin J. Evans, David Flanagan
Learning Java, 5th Edition

Learning Java, 5th Edition

Marc Loy, Patrick Niemeyer, Daniel Leuck
Learning Java, 4th Edition

Learning Java, 4th Edition

Patrick Niemeyer, Daniel Leuck

Publisher Resources

ISBN: 0596007736Supplemental ContentErrata Page