java钩子函数的应用已经kill
java钩子函数的使用已经kill
package com.aircoder.test;
import java.util.Date;
public class Test {
public static void sysLog(String str){
System.out.println(new Date()+"\t "+str);
}
public static void main(String[] args) {
System.out.println("\t\fHello world ");
sysLog("\t start service .....");
Runtime.getRuntime().addShutdownHook(new Thread(){
public void run(){
System.out.println("是结束了");
}
});
Runtime.getRuntime().addShutdownHook(new Thread(){
public void run(){
System.out.println("是结束了2");
}
});
//System.exit(1); kill 会执行,挨个执行钩子函数, kill -3 会打印线程堆栈,线程不会结束,kill -9 不会执行
while(true){
}
}
}
package com.aircoder.test;
import java.util.Date;
public class Test {
public static void sysLog(String str){
System.out.println(new Date()+"\t "+str);
}
public static void main(String[] args) {
System.out.println("\t\fHello world ");
sysLog("\t start service .....");
Runtime.getRuntime().addShutdownHook(new Thread(){
public void run(){
System.out.println("是结束了");
}
});
Runtime.getRuntime().addShutdownHook(new Thread(){
public void run(){
System.out.println("是结束了2");
}
});
//System.exit(1); kill 会执行,挨个执行钩子函数, kill -3 会打印线程堆栈,线程不会结束,kill -9 不会执行
while(true){
}
}
}