/Users/lyon/j4p/src/thread/ThreadTest.java

1    package thread; 
2     
3    public class ThreadTest 
4            implements Runnable { 
5     
6        Thread t = new Thread(this); 
7        int threadTestNumber = 0; 
8        public static int n = 1000; 
9     
10       ThreadTest() { 
11           t.start(); 
12           threadTestNumber = n; 
13           n++; 
14       } 
15    
16       public void sleep(long time) { 
17           try { 
18               Thread.sleep(time); 
19           } catch (InterruptedException e) { 
20               System.out.println(e); 
21           } 
22       } 
23    
24       public void run() { 
25           while (true) { 
26               synchronized (System.out) { 
27                   System.out.println( 
28                           ( 
29                           threadTestNumber + ":" + 
30                           new java.util.Date()).toString()); 
31               } 
32               sleep((int) (Math.random() * 1000)); 
33           } 
34       } 
35    
36       public static void main(String args[]) { 
37           for (int i = 0; i < 9000; i++) 
38               new ThreadTest(); 
39       } 
40   } 
41