The RuntimeException is not thrown directly by any of the methods in the thread classes; it is simply a base class that specifies a special group of exceptions. Runtime exceptions are considered so basic that it would be too tedious to check for every possible runtime exception that could be thrown (another reason is that these exceptions are generally bugs in the program). Unlike other exceptions, the compiler does not require that you handle a RuntimeException.

All of the following exceptions are runtime exceptions.


The IllegalThreadStateException is thrown by the thread classes when the thread is not in a state where it is possible to fulfill the request. This is caused by an illegal request made by the program and generally indicates a bug in the program. The following are the possible cases in the thread system where the IllegalThreadStateException is thrown:

The start() method

The Thread class provides the start() method, which starts a new thread (see Chapter 2). As we mentioned, a thread should be started only once. However, if a program calls the start() method of an already running thread, the IllegalThreadStateException is thrown.

The setDaemon() method

The Thread class provides the setDaemon() method, which specifies whether the thread is a daemon thread (see Chapter 6). As we mentioned, the daemon status of a thread must be set before the thread is started. If the setDaemon() method is called when the thread is already running, ...

Get Java Threads, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.