RunTime的回调钩子
写点笔记
共 1536字,需浏览 4分钟
·
2021-07-17 23:35
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);
}
}
评论