Zang Topher wrote:What if, thread has not updated the status in table since long (and thread has also not finished the process)? That is why I termed 'Thread is hanged' .
Welcome to CodeRanch!
As Paul has mentioned, it's quite difficult to understand the reason just by looking at the code. However, I would like to pin-point few things:
Firstly, what you termed 'hanged' might not be a system issue. Before troubleshooting the system, firstly, make sure that there is no problem with the code.
Now, the scenario you've mentioned - is it possible? I mean, does your code contains any part in which the thread does not update DB? Or thread waits for a specific condition to occur?
Secondly, after making sure that code works properly, put a lot of logging/print statements in your code(print each and every exception in the log - even if you are re-throwing it). Observe the logs. Is everything happening as per expectation (i.e. the flow)? e.g. a thread should not wait for a condition if the condition is already occurred.
If still you don't get lucky enough to understand the problem, but get lucky enough to reproduce the scenario, then take the thread dump (typically it is `kill -3 <PID of JVM>`) - unfortunately, I'm aware of this approach only on UNIX/Linux systems - not sure about other systems. But if it is possible to get the thread dump, then observe if there are any 'blocked' threads (especially the threads created via application). By the way, thread-dump output goes to stdout stream - so, it may be your console, or log file.
In case of deadlock, or 'system hung' kind of issues, I always follow this approach - and I need to take thread dump very rarely (most of the issues are identified at logging/print stage).
I hope this helps.