• 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

Dealing with hung threads

 
Bartender
Posts: 1357
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,
a relative common error in a java ee application is costituited by methods which result in hung threads (tipically because of an infinite loop, locks, conn leaks and so on). As far as I know, there is no way to forcibly stop a thread from outside in java.Common workarounds i have seen comprehend a thread hung notification system provided by appserver itself, but at the very end the only way to get rid of hung threads is to restart the jvm. That's a drastic solution. I wonder if there is a way to implement a kind of "thread execution timeout". In theory, if a thread could be made aware of the fact it's taking to long to execute its task,it may quits execution.
Any suggestion?
 
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
EE code should not manipulate threads directly at all. Generally speaking hung threads is a sign of the developer not following the correct EE practices so the solution there is to correct the offending code.

Sometimes the appserver itself is implemented in a way which results in hung threads. For these scenarios you should use the appserver provided tools. There will be nothing else that the developer can do.
 
Claude Moore
Bartender
Posts: 1357
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your reply. I'd like that a solution exist, just because it's quite annoying restart a server when hung threads occours - and developing is an error prone activity,things may go wrong.
 
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm with E Armitage on this one, hung threads occur because your application has a problem in it and the solution is to fix those problems in your application.

Claude Moore wrote:developing is an error prone activity,things may go wrong


While this is true it is our job as professional programmers to make them go right, as much as we are able, before the application hits production. To accept a hung thread as 'just one of those things' in production is unacceptable. It's a bug, fix it.
 
Claude Moore
Bartender
Posts: 1357
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're both right, of course. Hung thread is a symptom there's poorly written code around creating problems,so the very first step is to detect the problematic code and fix it.But in a production system, the more are the safety nets, the best is. I think the real problem would not be having a way to stop hung thread, but thinking "Ok, i can code with head turned off, just i have a way to escape problems".
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic