GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java
Go To First  |  Previous Question  |  Next Question 
 Core Java  |  Question 469 of 502    Print  
Illegal State of Exception
When does thread throws illegal state of exception?
Explain with two scenarios?



  
Total Answers and Comments: 3 Last Update: September 27, 2008     Asked by: dsureshkumar28 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: abuthahir.d
 
1.Whenever a dead thread is tried to start
2. When we try to start a running thread
 eg:
  Thread t = new Thread();
 t.start();
t.start();

throws IllegalThreadStateException

Above answer was rated as good by the following members:
shouvanik1979, swpnl_ptl, talktoatish
April 14, 2008 07:31:38   #1  
abuthahir.d Member Since: January 2008   Contribution: 9    

RE: Illegal State of Exception
1.Whenever a dead thread is tried to start
2. When we try to start a running thread
eg:
Thread t new Thread();
t.start();
t.start();

throws IllegalThreadStateException

 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 0Overall Rating: +2    
April 29, 2008 05:40:04   #2  
charankk Member Since: April 2008   Contribution: 5    

RE: Illegal State of Exception
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.


 
Is this answer useful? Yes | No
September 27, 2008 10:46:41   #3  
mkgraumt Member Since: September 2008   Contribution: 1    

RE: Illegal State of Exception
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();


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape