1public class InterruptedThread
2 extends Thread {
3
4 int cnt = 0;
5
6 public void run() {
7 System.out.println("thread: starting");
8
9 while ( ! isInterrupted() ) {
10
11 System.out.println("thread: the " + (++cnt) + ". time");
12
13 try {
14 sleep(500);
15 } catch (InterruptedException e) {
16 System.out.println("thread: InterruptedException catched");
17 interrupt();
18 }
19 }
20
21 System.out.println("thread: finished");
22 }
23}