aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Dealing with hung threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Dealing with hung threads" Watch "Dealing with hung threads" New topic
Author

Dealing with hung threads

Claude Moore
Ranch Hand

Joined: Jun 24, 2005
Posts: 453
    
    1

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

Joined: Mar 17, 2012
Posts: 892
    
    9
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

Joined: Jun 24, 2005
Posts: 453
    
    1

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
Bartender

Joined: Mar 28, 2008
Posts: 1016
    
  47

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.


Tim Driven Development
Claude Moore
Ranch Hand

Joined: Jun 24, 2005
Posts: 453
    
    1

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".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dealing with hung threads