Exception in thread “main” java.lang.IllegalThreadStateException

Posted: May 9, 2012 in Java

IllegalThreadStateException

It is child class of Runtime Exception and its is unchecked. It is raised programmatically when ever a method has invoked at illegal or in appropriate time.

Example 1:

After Starting a Thread we are not allowed to start the same thread again violation leads to illegalThreadStateException

public class Test extends Thread

{

public void run(){

System.out.println(“I am from run “);

}

public static void main(String[] args) {

Test test1 = new Test();

Thread thread = new Thread(test1);

thread.start();

thread.start();

}            }

output:

I am from run Exception in thread “main”
java.lang.IllegalThreadStateException
at java.lang.Thread.start(Thread.java:595)
at com.clarity.test1.main(test1.java:108)

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s