简体   繁体   中英

Application thread keeps running

We are using Websphere Work Manager (CommonJ) for spawning threads in our application. We are making use of the default WorkManager and through JNDI accessing it in our application.

try {  
    Context ctx = new InitialContext();  
    wm = (WorkManager) ctx.lookup("java:comp/env/wm/App_WORKMANAGER");  
    wm.schedule(this);  
    //threadScheduler = new Thread(this);  
    //threadScheduler.start();  
} catch (Exception e) {  
    // catch the exception  
} 

We keep running the threads which listens to different queues to check for any message and process it. We do get hung messages as below , came to know this can be configured from admin console to stop showing the warning/error or increase the hung detection time.

[1/30/13 6:50:38:708 EST] 00000032 ThreadMonitor W WSVR0605W: Thread "WorkManager.DefaultWorkManager : 2" (00000022) has been active for 708969 milliseconds and may be hung. There is/are 1 thread(s) in total in the server that may be hung.

Now if we stop the application from admin console, these thread don't get stopped and we keep getting the Hung messages. For another deployment another set of threads adds up to the Hung thread count. I read somewhere that if we declare thread as Daemon then they get stopped (). So is it fine that we declare the threads as Daemon as below or we need to override the release() method too? Our release() is empty as of now.

public boolean isDaemon() {                        
  return true;  
}  

public void release() {  
 //TODO  
}

How exactly can we stop the application thread from running once the application is stopped? It's an old application using Struts 1.x .

I read two explanation here:

  1. Thread keeps running even after application has been stopped in Websphere (as I'm not using spring, just declaring Deamon is fine? And this will work if we stop the JVM itself, just stopping app from console wont help, correct?)

  2. Does Websphere respect Daemon threads? (the approach suggested by Sarel Botha is the only solution or we have some setting from console to get the job done.)

Thanks.

Yes, in your use case the isDaemon method should return true and you need to implement the release method in such a way that it stops the code executing in the run method of the Work object. If you do this, then the hanging thread warnings will disappear, and WebSphere will call release on all running Work objects when the application is stopped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM