日期:2014-05-20 浏览次数:20808 次
package core.test; import org.apache.log4j.Logger; import sun.misc.Signal; import sun.misc.SignalHandler; public class SignalHandlerTest { public static void main(String... args) throws Exception { final Logger log = Logger.getLogger(SignalHandlerTest.class); SignalHandler handler = new SignalHandler() { public void handle(Signal signal) { log.info(signal.getName()); System.exit(-1); } }; Signal.handle(new Signal("TERM"), handler);//相当于kill -15 Signal.handle(new Signal("INT"), handler);//相当于Ctrl+C for (;;) { Thread.sleep(1000); } } }
------解决方案--------------------