@Override public void run() { System.out.println("Shutting down..."); // create an exit thread that forces a shutdown if the JVM wont exit cleanly SystemExit exit = new SystemExit(5000); exit.setDaemon(true); exit.start(); try { // stop the channel channel.stop(Channel.DEFAULT); } catch (Exception x) { x.printStackTrace(); } System.out.println("Channel stopped."); }
/** Blocks until stopped in a timely fashion (see {@link org.sonar.process.StopperThread}) */ void stop() { stopAsync(); try { // stopperThread is not null for sure // join() does nothing if thread already finished stopperThread.join(); lifecycle.tryToMoveTo(Lifecycle.State.STOPPED); } catch (InterruptedException e) { // nothing to do, the process is going to be exited } exit.exit(0); }
@Override public void run() { exit.setInShutdownHook(); stop(); }