1 package org.apache.helix.filestore;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.Date;
25 import java.util.List;
26 import java.util.concurrent.Callable;
27 import java.util.concurrent.ExecutorService;
28 import java.util.concurrent.Executors;
29 import java.util.concurrent.Future;
30 import java.util.concurrent.atomic.AtomicReference;
31
32 public class Test
33 {
34 public static void main(String[] args) throws InterruptedException
35 {
36 while(true){
37 ExecutorService service = Executors.newFixedThreadPool(400);
38 List<Callable<Object>> list = new ArrayList<Callable<Object>>();
39 for (int i = 0; i < 256; i++)
40 {
41 MyRunnable runnable = new MyRunnable();
42 list.add(runnable);
43 new Thread(runnable).start();
44
45 }
46
47
48
49 System.out.println("RUN -------------");
50 Thread.sleep(5000);
51 }
52 }
53 }
54
55 class MyRunnable implements Callable<Object>,Runnable
56 {
57
58
59 class Ref
60 {
61 Object obj;
62
63 public Ref(Object obj)
64 {
65 this.obj = obj;
66 }
67
68 void set(Object obj)
69 {
70 this.obj = obj;
71 }
72
73 Object get()
74 {
75 return obj;
76 }
77 }
78
79 Ref ref = new Ref(new Object());
80 Object lock = new Object();
81
82
83 public Object call1() throws Exception
84 {
85 long start = System.currentTimeMillis();
86 System.out.println(start);
87 synchronized (lock)
88 {
89
90 if (ref.get() != null)
91 {
92 try
93 {
94 int sum = 0;
95 List<Float> array = new ArrayList<Float>();
96 for (int i = 0; i < 5000; i++)
97 {
98 array.add((float) Math.random());
99 }
100 Collections.sort(array);
101 } catch (Exception e)
102 {
103 e.printStackTrace();
104 }
105 ref.set(null);
106 }
107 }
108 long end = System.currentTimeMillis();
109 System.out.println("time:" + (end - start));
110 return new Object();
111
112 }
113
114 @Override
115 public Object call() throws Exception
116 {
117 long start = System.currentTimeMillis();
118 System.out.println(start);
119 try
120 {
121
122
123
124
125
126
127
128 } catch (Exception e)
129 {
130 e.printStackTrace();
131 }
132 ref.set(null);
133 long end = System.currentTimeMillis();
134 System.out.println("time:" + (end - start));
135 return new Object();
136
137 }
138
139 @Override
140 public void run()
141 {
142 long start = System.currentTimeMillis();
143 System.out.println(start);
144 try
145 {
146 int sum = 0;
147 List<Float> array = new ArrayList<Float>();
148 for (int i = 0; i < 5000; i++)
149 {
150 array.add((float) Math.random());
151 }
152 Collections.sort(array);
153 } catch (Exception e)
154 {
155 e.printStackTrace();
156 }
157 ref.set(null);
158 long end = System.currentTimeMillis();
159 System.out.println("time:" + (end - start));
160 }
161 }
162