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