RunTime的回调钩子
2)使用System.exit()
3)终端使用Ctrl+C触发的中断
4)系统关闭
public class TestRunTime {
static class MyThreadOne extends Thread{
public void run(){
System.out.println("stop thread one~~~~");
}
}
static class MyThreadTwo extends Thread{
public void run(){
System.out.println("stop thread two~~~~");
}
}
public static void main(String[] args) {
MyThreadOne myThreadOne=new MyThreadOne();
MyThreadTwo myThreadtwo=new MyThreadTwo();
Runtime.getRuntime().addShutdownHook(myThreadOne);
Runtime.getRuntime().addShutdownHook(myThreadtwo);
}
}
评论