• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dealing with hung threads

 
Claude Moore
Ranch Hand
Posts: 806
7
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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?
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 806
7
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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.
 
Tim Cooke
Sheriff
Pie
Posts: 3079
127
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 806
7
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic