Java – How to prevent a long running SQL query from looking stuck

javamultithreading

If I had a method like:

private void someMethod()
{
    runSqlQueryA();
    runSqlQueryB();
    runSqlQueryC();
}

My understanding is this method will be one thread.

In weblogic, the thread will appear stuck if it's been running for longer than 10 minutes (by default).

My question is – if these SQL queries are routinely take a long time, how do I prevent Weblogic from detecting the thread as stuck?

One option would be to simply change the stuck thread threshold, but I'm wondering if there's a better solution, such as a java thread manager that keeps it refreshed.

Best Answer

WebLogic is mainly a web application container. As such, anything that take minutes (more than a few seconds) to process will be suspect. Threads flagged as stuck is an indication that something may be wrong. If you end up with too many stuck threads, the server is likely to get in a very bad state. Other than modifying the times or running on an un-managed (by WebLogic) thread pool there is little you can do not to have a long running thread from looking stuck. Using your own thread pool can cause significant performance issues.

If you have processes that take this long, you may want to use JMS or some other queuing system to process them. This will allow you to limit the number of concurrent processes running this slow process. The queue could be processed on a separate JVM with appropriately modified stuck thread times.

If the queries can run in parallel, then it may be possible to queue multiple JMS items. These would be less likely to run long enough to appear stuck.

As designed you will get thread flagged as stuck. This is not necessarily an issue unless you generate too many such threads, or they never complete. It is likely worthwhile examining other options rather than a container for running the process