當(dāng)幸福來(lái)敲門(mén)

          我就會(huì)牢牢抓住!
          隨筆 - 50, 文章 - 3, 評(píng)論 - 8, 引用 - 0
          數(shù)據(jù)加載中……

          線程等待問(wèn)題處理

          class MyThread implements Runnable {
          @Override
          public void run() {
            System.out.println("1、進(jìn)入run()方法休眠");
            try {
             System.out.println("2、線程休眠20秒");
             Thread.sleep(20000);//這里休眠20秒
             System.out.println("3、線程正常休眠完畢");
            } catch (InterruptedException e) {
             System.out.println("4、線程發(fā)生異常休眠被中斷");
             return;//返回方法調(diào)用處
            }
            System.out.println("5、線程正常結(jié)束run()方法體");
          }
          }
          public class InterruptDemo {

          public static void main(String[] args) {
            MyThread mt = new MyThread();
            Thread t = new Thread(mt,"線程A");
            t.start();//啟動(dòng)線程
          //========================================================
            try {
             Thread.sleep(2000);  //保證線程至少執(zhí)行2秒
            } catch (InterruptedException e) {
             e.printStackTrace();
            }
          //========================================================
            t.interrupt();//中斷線程
          }
          }

          posted on 2012-06-21 15:21 wyx 閱讀(207) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 芜湖市| 原阳县| 邢台县| 昌都县| 四川省| 安阳县| 鹤庆县| 盐津县| 方山县| 闽清县| 济宁市| 延庆县| 鄂托克前旗| 花垣县| 凉山| 石家庄市| 江都市| 利川市| 金溪县| 桦川县| 亳州市| 桐柏县| 旬邑县| 伽师县| 呼和浩特市| 涡阳县| 抚州市| 安溪县| 甘德县| 邵阳市| 分宜县| 临猗县| 襄垣县| 红原县| 正镶白旗| 富顺县| 铜川市| 海伦市| 尤溪县| 兰考县| 栾川县|