Runtime.getRuntime().addShutdownHook(shutdownHook);
package cn.cmcc.test;
public class ShutDownTest {
/**
* @param args
*/
public static void main(String[] args) {
// 定义线程1
Thread thread1 = new Thread() {
public void run() {
System.out.println("thread1...");
}
};
// 定义线程2
Thread thread2 = new Thread() {
public void run() {
System.out.println("thread2...");
}
};
// 定义关闭线程
Thread shutdownThread = new Thread() {
public void run() {
System.out.println("shutdownThread...");
}
};
// jvm关闭的时候先执行该线程钩子
Runtime.getRuntime().addShutdownHook(shutdownThread);
thread1.start();
thread2.start();
}
}
thread1...
shutdownThread...
thread2...
shutdownThread...
1335



被折叠的 条评论
为什么被折叠?



