• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to kill a Thread which is reading Data

 
Sudarshan Muramreddy
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Set a flag on your Runnable class and have the object instance check its copy periodically and exit if it is a certain value.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic