魚躍于淵

          First know how, Second know why !
          posts - 0, comments - 1, trackbacks - 0, articles - 49

          shut down Thread

          Posted on 2008-12-06 11:34 魚躍于淵 閱讀(171) 評論(0)  編輯  收藏 所屬分類: j2se
           1 import java.util.*;
           2 
           3 public class ThreadTest2{
           4     public static void main(String[] args){
           5         MyThread mt = new MyThread();
           6         mt.start();
           7         try{
           8             Thread.sleep(10000);
           9         }catch(InterruptedException ex){
          10             
          11         }
          12         mt.shutDown();
          13         //mt.interrupt();
          14     }
          15 }
          16 
          17 class MyThread extends Thread{
          18     boolean flag = true;
          19     public void run(){
          20         while(flag){
          21             System.out.println("==========" + new Date() + "===========");
          22             try{
          23                 sleep(1000);
          24             }catch(InterruptedException ex){
          25                 return ;
          26             }
          27         }
          28     }
          29     public void shutDown(){
          30         flag = false;
          31     }
          32 }
          主站蜘蛛池模板: 双鸭山市| 龙江县| 新宾| 浦北县| 喀喇沁旗| 留坝县| 桃江县| 武邑县| 乐业县| 呼和浩特市| 银川市| 卢湾区| 南岸区| 洪雅县| 斗六市| 永登县| 临颍县| 望谟县| 屯昌县| 洪雅县| 荣昌县| 林州市| 德阳市| 襄樊市| 滨州市| 遂宁市| 社旗县| 江山市| 浪卡子县| 金堂县| 新巴尔虎右旗| 宿迁市| 彭山县| 古交市| 美姑县| 杂多县| 周口市| 乐至县| 清苑县| 和林格尔县| 桑日县|