1
2
3
4
5
6
7
8public
9class SimpleThread extends Thread {
10
11
12
13 public
14 SimpleThread(String name) {
15 super(name);
16 }
17
18
19
20 public
21 void run() {
22
23 for (int i = 1;
24 i <= 10;
25 ++i ) {
26 System.out.println(getName() + " the " + i + ". time");
27 doSomething();
28 }
29
30 System.out.println(getName() + " finished");
31 }
32
33
34
35 public
36 void doSomething() {
37 try {
38
39
40
41 sleep( (int)(Math.random() * 500) );
42 }
43 catch ( InterruptedException e ) { }
44 }
45
46}