All ITKnowledge Source Code Search Tips Advanced Search |

| Mastering Java Threads by Marc Adler and David Herst DDC Publishing, Inc. ISBN: 1562438425 Pub Date: 05/01/99

Search this book:

Previous | Table of Contents | Next

## Chapter 4
The Thread Class in Detail

Lesson Topics

  • Variables
  • Behind the Scenes: The Thread Class in C

### Variables

All variables deal with the priority of the thread.

  • public final static int MIN_PRIORITY: the minimum priority that a Thread can have. The most minimal priority is equal to 1.
  • public final static int NORM_PRIORITY: the default priority that is assigned to a Thread. The default priority is equal to 5.
  • public final static int MAX_PRIORITY: the maximum priority that a Thread can have. The max priority value a Thread can have is 10.

#### Methods

Table 4-1: Thread methods
Constructor | Description
--- | ---
Thread() | Constructs a new Thread.
Thread(Runnable) | Constructs a new Thread; applies the run() method of the specified target.
Thread(ThreadGroup, Runnable) | Constructs a new Thread in the specified Thread group; applies the run() method of the specified target.
Thread(String) | Constructs a new Thread with the specified name.
Thread(ThreadGroup, String) | Constructs a new Thread in the specified Thread group with the specified name.
Thread(Runnable, String) | Constructs a new Thread with the specified name and applies the run() method of the specified target.
Thread(ThreadGroup, Runnable, String) | Constructs a new Thread in the specified Thread group with the specified name and applies the run() method of the specified target.

Thread Body

The run() method is the actual body of this Thread.

Methods That Query & Change the State of a Thread

Table 4-2: Methods that query and change the state of a thread
Method | Description
--- | ---
destroy() | Destroy a threads without any cleanup.
isAlive() | Returns a boolean indicating if the Thread is active. A thread is active if it is in Runnable or Not Runnable state. It is not active if it is in a Dead or New state.
resume() | Resumes this Thread execution.
sleep(long) | Causes the currently executing Thread to sleep for the specified number of milliseconds.
sleep(long, int) | Sleep, in milliseconds and additional nanosecond.
start() | Starts this Thread.
stop() | Stops a Thread asynchronously.
stop(Throwable) | Stops a Thread asynchronously by throwing an object.
suspend() | Suspends this Thread’s execution.
yield() | Causes the currently executing Thread object to yield.

Thread Attributes

Table 4-3: Thread attributes
Attribute | Description
--- | ---
countStackFrames() | Returns the number of stack frames in this Thread.
getName() | Gets and returns this Thread’s name.
getThreadGroup() | Gets and returns this Thread group.
setName(String) | Sets the Thread’s name.
toString() | Returns a String representation of the Thread, including the thread’s name, priority, and thread group.

Priority

getPriority() | Gets and returns the Thread’s priority.
setPriority(int) | Sets the Thread’s priority.

Previous | Table of Contents | Next

Copyright © DDC Publishing

Products | Contact Us | About Us | Privacy | Ad Info | Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.