jvm hookはどのようにeclipseでデバッグします
1613 ワード
debug状態で、コードはSystemを終了することができる.exit(0)、ブレークポイントを変更します.
ref:
http://stackoverflow.com/questions/12836551/shutdownhook-in-eclipse
package com.cmbchina.nastool;
import java.util.Date;
public class Console {
public static void main(String[] args) {
final WriteService writeService = new WriteService();;
final ReadService readService = new ReadService();
System.out.println(ContextManager.DATETIME_FORMAT.format(new Date()));
//start write NAS service
if(ContextManager.getConfig().isEnableWriteTest()){
System.out.println("write NAS service starting...");
writeService.start();
}
//start read NAS service
if(ContextManager.getConfig().isEnableReadTest()){
System.out.println("read NAS service starting...");
readService.start();
}
// jvm hook
Runtime.getRuntime().addShutdownHook(new Thread(){
public void run() {
//stop write service
if(ContextManager.getConfig().isEnableWriteTest()){
writeService.stop();
System.out.println("write NAS service stop!");
}
//stop read service
if(ContextManager.getConfig().isEnableReadTest()){
readService.stop();
System.out.println("read NAS service stop!");
}
//save max seq no
long maxFileSeq = ContextManager.getFileHelper().getNewFileSeq();
System.out.println("max file seq:" + maxFileSeq);
System.out.println("all services stop successfully!");
System.out.println(ContextManager.DATETIME_FORMAT.format(new Date()));
}
});
//System.exit(0);
}
}
ref:
http://stackoverflow.com/questions/12836551/shutdownhook-in-eclipse