Embedded OpenMQ HA broker not shutting down due to Non deamon thread

60 Views Asked by At

The com.sun.messaging.jmq.jmsserver.service.HAMonitorService class contains HATimerThread which starts a java Thread which then runs it ( HATimerThread is a Runnable ).

This thread is not a deamon thread.

The code for run is as follows;

 public void run() {
            while (true) {
                long time = System.currentTimeMillis();
                synchronized(this) {
                    if (time < nexttime) {
                        try {
                            this.wait(nexttime  - time);
                        } catch (InterruptedException ex) {}
                        continue;
                     } else {
                         child.run();
                     }
                 }
                 if (repeatItr == 0) break;
                 time = System.currentTimeMillis();
                 long tmpnext = nexttime + repeatItr;
                 if (time >= tmpnext) { 
                     nexttime = time;
                 } else {
                     nexttime = tmpnext;
                 }
            }      

        }

The only way this thread can exit is if repeatItr == 0. However once set in the constructor (which is called by HAMonitorService's constructor which calls it such that it is non 0) nothing seems to change it. This means the loop is never exited, which means in turn the thread never stops, and since it is not a daemon thread then the VM will never shut down.

Is this a bug or is there some other mechanism which stops it which I have not thought about? At the moment the process running my Embedded cluster broker never exits because of this even though the rest of it shutsdown cleanly...

Tried this uses 4.5.2 and 5.1.

I rebuilt the source for 5.1 setting the thread created by HATimerThread to be a deamon and everything works fine now.

1

There are 1 best solutions below

0
On BEST ANSWER

According to Amy Kang of Oracle

"The HATimerThread in HAMonitorService is supposed to run as long as the broker is not terminating or util broker calls System.exit() to terminiate or restart itself. However it can be made daemon thread."

see OpenMq users forum