File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes why you have to catch InterruptedException Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "why you have to catch InterruptedException " Watch "why you have to catch InterruptedException " New topic
Author

why you have to catch InterruptedException

suneel kanth
Greenhorn

Joined: Feb 06, 2003
Posts: 22
Hi all,
I have a basic doubt in the Thread concept.?Pls help me to find the sol.Thank you..


Any sufficiently advanced bug is indistinguishable from a feature.
Leandro Oliveira
Ranch Hand

Joined: Nov 07, 2002
Posts: 298
when you have a thread and you want to stop it you can call on this thread the method interrupt(), but this interrupt method will only set a variable of type boolean to true, every call to this.isInterrupted() will return the value of this variable. The only problem is: your thread goes to the not running state, any call to interrupt() will, specially in this case, restart the thread and then throw new InterruptedException(), conclusion: InterruptedException must be catch whenever you intend to make the thread sleep, or wait, if the thread is interrupted in the running state no exceptions are thrown, if it is sleeping, it's dreams will be interrupted and then a new InterruptedException will be created!!!
Please, correct me if I'm wrong. Hope this helps!
 
 
subject: why you have to catch InterruptedException
 
Threads others viewed
Array in reverse order......?
IBM to laid-off: Want a job in India?
Sound Card Unavailable in Hardware Error
Canada Allowances by SATYAM / TCS.
JSP: Unable to connect to mysql in local drive [Solved]
MyEclipse, The Clear Choice

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture