IllegalThreadStateException in Java

Share and Enjoy !

Class IllegalThreadStateException in Java

IllegalThreadStateException is thrown from code to indicate that the thread is not in an appropriate state for the required or requested operation. The call to sleep() method is enclosed with a try block followed by a catch block. The sleep() method may throw an exception, which needs to be caught and handle.
Java throws IllegalThreadStateException whenever we attempt to invoke a method that a thread can not handle in the given state.


A sleeping thread can not deal with the resume() method as a sleeping thread can not receive any messages or instructions. It is even true with the suspend() method when it is used on a blocked(Not runnable) thread.

or The thread maybe already started and running when we want to start the same thread.

The structure of the class IllegalThreadStateException is as follows:

public class java.lang.IllegalThreadStateException extends java.lang.IllegalArgumentException{
public IllegalThreadStateException();
//constructs an empty IllegalThreadStateException object that is an object with no message specified.
public IllegalThreadStateException(String message);
//constructs an IllegalThreadStateException object with the message specified.

The class IllegalThreadStateException also inherits methods from class Object and Throwable.

From Object classFrom Throwable class
wait(long, int)getLocalizedMessage()

Share and Enjoy !

READ  ArithmeticException in Java

Leave a Reply

Your email address will not be published. Required fields are marked *