1 import java.util.*;
 2 
 3 public class TestInterrupt {
 4     public static void main(String[] args){
 5         MyThread thread =new MyThread();
 6         thread.run();
 7         try{Thread.sleep(10000);}
 8         catch (InterruptedException e){}
 9         thread.interrupt();
10     }
11 }
12 
13 class MyThread extends Thread{
14     boolean flag =true;
15     public void run() {
16         while(flag){
17             System.out.println("==="+new Date()+"===");
18             try {
19                 sleep(1000);
20             }
21             catch (InterruptedException e) {
22                 return;
23             }
24         }
25     }
26     
27 }