• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Kill a worker thread hung in IO

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When a worker thread is hung in a synchronous IO operation (such as a JDBC call) here is a trick I developed on how to kill the worker thread as well as the supervisory thread.
You may say "but this is brute force, not very elegant!"
Well, at least this brute solution works!
Try using interrupt() or stop() (deprecated, by the way). The worker thread does not respond at all...
So this is the only solution I found.
Enjoy!

/**
* Start thread
*/

public void run () {
cat.debug(Thread.currentThread().getName() + " thread started.");

if (Thread.currentThread().getName().equalsIgnoreCase("SUPERVISOR")) {
try {
Thread.currentThread().sleep(10000);
} catch (InterruptedException e) {}

//Supervisor wokeup

if (queryInProgress) {
stopProcessing = true;
cat.debug(worker.thread.getName() + " will be aborted by supervisory monitor. Query exceeded threshold.");
Runtime.getRuntime().exit(1);
}
}
else {
//Worker thread
worker.sequenceProcessing();
}
}
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I, on the other hand, close the IO channel from a seperate thread.
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I, on the other hand, close the IO channel from a seperate thread.


A much wiser approach. Kinda like the difference between tapping somebody on the shoulder and hitting them in th face with a frying pan to get their attention.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since the example given is a JDBC call, I think the preferred solution is to call cancel() on the Statement executing the call (assuming the driver supports it.) Same basic idea though.
Still, while the frying pan usually shouldn't be the first choice, it's worth remembering that the option is available, as it may be necessary sometime...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic