@Override
    public void stop()
    {
        synchronized (killHook)
        {
            jqmlogger.info("JQM engine " + this.node.getName() + " has received a stop order");

            // Kill hook should be removed
            try
            {
                if (!Runtime.getRuntime().removeShutdownHook(killHook))
                {
                    jqmlogger.error("The engine could not unregister its shutdown hook");
                }
            }
            catch (IllegalStateException e)
            {
                // This happens if the stop sequence is initiated by the shutdown hook itself.
                jqmlogger.info("Stop order is due to an admin operation (KILL/INT)");
            }
        }

        // Stop pollers
        int pollerCount = pollers.size();
        for (QueuePoller p : pollers.values())
        {
            p.stop();
        }

        // Scheduler
        this.scheduler.stop();

        // Jetty is closed automatically when all pollers are down

        // Wait for the end of the world
        if (pollerCount > 0)
        {
            try
            {
                this.ended.acquire();
            }
            catch (InterruptedException e)
            {
                jqmlogger.error("interrupted", e);
            }
        }

        // Send a KILL signal to remaining job instances, and wait some more.
        if (this.getCurrentlyRunningJobCount() > 0)
        {
            this.runningJobInstanceManager.killAll();
            try
            {
                Thread.sleep(10000);
            }
            catch (InterruptedException e)
            {
                jqmlogger.error("interrupted", e);
            }
        }

        jqmlogger.debug("Stop order was correctly handled. Engine for node " + this.node.getName() + " has stopped.");
    }
@ Override public void stop ( ) { synchronized ( killHook ) { jqmlogger . info ( "JQM engine " + this . node . getName ( ) + " has received a stop order" ) ; try { if ( ! Runtime . getRuntime ( ) . removeShutdownHook ( killHook ) ) { jqmlogger . error ( "The engine could not unregister its shutdown hook" ) ; } } catch ( IllegalStateException e ) { jqmlogger . info ( "Stop order is due to an admin operation (KILL/INT)" ) ; } } int pollerCount = pollers . size ( ) ; for ( QueuePoller p : pollers . values ( ) ) { p . stop ( ) ; } this . scheduler . stop ( ) ; if ( pollerCount > 0 ) { try { this . ended . acquire ( ) ; } catch ( InterruptedException e ) { jqmlogger . error ( "interrupted" , e ) ; } } if ( this . getCurrentlyRunningJobCount ( ) > 0 ) { this . runningJobInstanceManager . killAll ( ) ; try { Thread . sleep ( 10000 ) ; } catch ( InterruptedException e ) { jqmlogger . error ( "interrupted" , e ) ; } } jqmlogger . debug ( "Stop order was correctly handled. Engine for node " + this . node . getName ( ) + " has stopped." ) ; }
Gracefully stop the engine