wood burning stoves 2.0*
The moose likes Java in General and the fly likes How to kill a Thread which is reading Data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to kill a Thread which is reading Data" Watch "How to kill a Thread which is reading Data" New topic
Author

How to kill a Thread which is reading Data

Sudarshan Muramreddy
Greenhorn

Joined: Jun 08, 2004
Posts: 16
HI All,
Is there any way we can kill a thread which is reading data with out using stop method(i think Sun is going to depricate this method).
which typically could occur when user tries to read a file using java.IO API.

Regards,
Sudarshan
Fletcher Estes
Ranch Hand

Joined: Jul 01, 2004
Posts: 108
This would generally be done using the interrupt() method. If your thread is blocked on any I/O read/write and its interrupt method is called, a ClosedByInterruptException will be thrown, which you can catch and deal with gracefully in the thread.

You should take a look at the JavaDocs for the Thread class.
Anton Golovin
Ranch Hand

Joined: Jul 02, 2004
Posts: 476
Set a flag on your Runnable class and have the object instance check its copy periodically and exit if it is a certain value.


Anton Golovin (anton.golovin@gmail.com) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to kill a Thread which is reading Data
 
Similar Threads
Stopping java thread using kill command line
How can I really stop/kill a thread?
killing a Thread ?
Stopping java thread using kill command line
UrlyBird - RMI server and Data design issues