posts - 93,  comments - 2,  trackbacks - 0
           這個方法的含義說明:
              這個方法的意思就是在jvm中增加一個關閉的鉤子,當jvm關閉的時候,會執行系統中已經設置的所有通過方法addShutdownHook添加的鉤子,當系統執行完這些鉤子后,jvm才會關閉。所以這些鉤子可以在jvm關閉的時候進行內存清理、對象銷毀等操作。
          測試類如下:
          1. public class RunTimeTest {
          2. /**
          3. * @param args
          4. */
          5. public static void main(String[] args) {
          6. Thread thread1 = new Thread() {
          7. public void run() {
          8. System.out.println("thread1...");
          9. }
          10. };
          11. Thread thread2 = new Thread() {
          12. public void run() {
          13. System.out.println("thread2...");
          14. }
          15. };
          16. Thread shutdownThread = new Thread() {
          17. public void run() {
          18. System.out.println("shutdownThread...");
          19. }
          20. };
          21. Runtime.getRuntime().addShutdownHook(shutdownThread);
          22. thread1.start();
          23. thread2.start();
          24. }
          25. }

          打印結果為:
          thread2...
          thread1...
          shutdownThread...

          或者:
          thread2...
          thread1...
          shutdownThread...

          結論:
          無論是先打印thread1還是thread2,shutdownThread 線程都是最后執行的(因為這個線程是在jvm執行關閉前才會執行)。

          posted on 2013-05-23 16:34 Terry Zou 閱讀(239) 評論(0)  編輯  收藏 所屬分類: Android
          <2013年5月>
          2829301234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          收藏夾

          Java

          搜索

          •  

          最新隨筆

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 周至县| 上饶市| 庄浪县| 怀化市| 佛坪县| 南江县| 安达市| 塔城市| 名山县| 尼勒克县| 樟树市| 惠水县| 宝坻区| 永泰县| 临桂县| 龙里县| 澎湖县| 昆山市| 旌德县| 永吉县| 宿迁市| 南昌县| 宁德市| 宁海县| 开鲁县| 苏尼特右旗| 南丹县| 济源市| 农安县| 富源县| 郑州市| 武清区| 永城市| 无极县| 慈利县| 博客| 全椒县| 隆德县| 武城县| 临泉县| 井研县|