船過水無痕

Java | Web | Architecture
posts - 12, comments - 0, trackbacks - 0, articles - 0
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

ShutdownHook

Posted on 2010-10-14 09:54 zdxue 阅读(163) 评论(0)  编辑  收藏
 1 public class App {
 2 
 3     public static void main(String[] args) {
 4         System.out.println(1);
 5         Runtime.getRuntime().addShutdownHook(new Thread(new AppExitHook()));
 6         System.out.println(2);
 7         System.exit(0);//
 8         //Runtime.getRuntime().halt(0); //强行终止
 9         System.out.println(3);
10     }
11 }
12

1 public class AppExitHook implements Runnable {
2 
3     public void run() {
4         System.out.println("App exit hook running");
5     }
6 
7 }
8 

只有注册用户登录后才能发表评论。


网站导航: