Illegal State of Exception

When does thread throws illegal state of exception?
Explain with two scenarios?

Questions by dsureshkumar28

Showing Answers 1 - 9 of 9 Answers

charankk

  • Apr 29th, 2008
 

Hi,
There are one scenario where we can use it as shown below.
Two threads within the JVM both gain access to the same  object. One thread invalidates the object and then the other thread attempts to use the same object where its been not exists.

In this scenarios jvm thows the java.lang.IllegalStateException.

  Was this answer useful?  Yes

mkgraumt

  • Sep 27th, 2008
 

Any attempt to change the status after the thread has been started, throws an IllegalThreadstateException.

Scenerio 1

If a thread has already started and you try to call method setDaemon(boolean) on thread

t.setDaemon(true);

Scenerio 2

If you call start() method on a thread which has already been started, it will throw IllegalThreadstateException.

t.start();

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions