1 package test; 2 3 import java.io.*; 4 5 public class Test11 { 6 7 static Test11 t; 8 Object [] objArray; 9 10 static class C { 11 public C(int i) { 12 this.i = i; 13 } 14 public int i; 15 } 16 17 public void test(C c) { 18 System.out.println("test"); 19 System.out.println(c.i); 20 } 21 22 public static void main(String [] args) { 23 System.out.println("main"); 24 try { 25 t = new Test11(); 26 int numObj = 100; 27 System.out.println("Generating " + numObj + " objects"); 28 t.objArray = new Object [numObj]; 29 for (int i = 0; i < t.objArray.length; i++) { 30 t.objArray[i] = new Object (); 31 if (i % 1000 == 0) 32 System.out.println(i); 33 } 34 System.out.println("Generated " + numObj + " objects"); 35 36 for (int i = 0; i < 15; i++) { 37 Thread th = new Thread (new Runnable () { 38 public void run() { 39 System.out.println("Thread running."); 40 while (true) { 41 t.test(new C(1)); 42 } 43 } 44 }); 45 th.setDaemon(true); 46 th.start(); 47 } 48 49 BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); 50 r.readLine(); 51 52 } catch (Throwable e) { 53 e.printStackTrace(); 54 } 55 } 56 } | Popular Tags |