鱼跃于渊

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

shut down Thread

Posted on 2008-12-06 11:34 鱼跃于渊 阅读(165) 评论(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 }

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


网站导航: