|
@@ -1,8 +1,10 @@
|
1
|
1
|
package com.xxl.controller;
|
2
|
2
|
|
|
3
|
+import java.text.MessageFormat;
|
3
|
4
|
import java.util.HashMap;
|
4
|
5
|
import java.util.List;
|
5
|
6
|
import java.util.Map;
|
|
7
|
+import java.util.concurrent.TimeUnit;
|
6
|
8
|
|
7
|
9
|
import org.apache.commons.lang.StringUtils;
|
8
|
10
|
import org.quartz.CronExpression;
|
|
@@ -136,4 +138,60 @@ public class IndexController {
|
136
|
138
|
return "job/help";
|
137
|
139
|
}
|
138
|
140
|
|
|
141
|
+ private int simpleParam = 0;
|
|
142
|
+ private ThreadLocal<Integer> tlParam;
|
|
143
|
+
|
|
144
|
+ @RequestMapping("/beat")
|
|
145
|
+ @ResponseBody
|
|
146
|
+ public String beat() {
|
|
147
|
+ if (tlParam == null) {
|
|
148
|
+ tlParam = new ThreadLocal<Integer>();
|
|
149
|
+ }
|
|
150
|
+ if (tlParam.get() == null) {
|
|
151
|
+ tlParam.set(5000);
|
|
152
|
+ }
|
|
153
|
+ simpleParam++;
|
|
154
|
+ tlParam.set(tlParam.get() + 1);
|
|
155
|
+
|
|
156
|
+ long start = System.currentTimeMillis();
|
|
157
|
+ try {
|
|
158
|
+ TimeUnit.SECONDS.sleep(1);
|
|
159
|
+ } catch (InterruptedException e) {
|
|
160
|
+ e.printStackTrace();
|
|
161
|
+ }
|
|
162
|
+ long end = System.currentTimeMillis();
|
|
163
|
+ return MessageFormat.format("cost:{0}, hashCode:{1}, simpleParam:{2}, tlParam:{3}",
|
|
164
|
+ (end - start), this.hashCode(), simpleParam, tlParam.get());
|
|
165
|
+ }
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+ public static void main(String[] args) {
|
|
169
|
+ Runnable runa = new Runnable() {
|
|
170
|
+ private int simInt = 0;
|
|
171
|
+ private ThreadLocal<Integer> tlParam = new ThreadLocal<Integer>();
|
|
172
|
+ @Override
|
|
173
|
+ public void run() {
|
|
174
|
+ while (true) {
|
|
175
|
+ try {
|
|
176
|
+ TimeUnit.SECONDS.sleep(1);
|
|
177
|
+ } catch (InterruptedException e) {
|
|
178
|
+ e.printStackTrace();
|
|
179
|
+ }
|
|
180
|
+
|
|
181
|
+ if (tlParam.get() == null) {
|
|
182
|
+ tlParam.set(0);
|
|
183
|
+ }
|
|
184
|
+ simInt++;
|
|
185
|
+ tlParam.set(tlParam.get()+1);
|
|
186
|
+ System.out.println(Thread.currentThread().hashCode() + ":simInt:" + simInt);
|
|
187
|
+ System.out.println(Thread.currentThread().hashCode() + ":tlParam:" + tlParam.get());
|
|
188
|
+ }
|
|
189
|
+ }
|
|
190
|
+ };
|
|
191
|
+
|
|
192
|
+ Thread t1 = new Thread(runa);
|
|
193
|
+ Thread t2 = new Thread(runa);
|
|
194
|
+ t1.start();
|
|
195
|
+ t2.start();
|
|
196
|
+ }
|
139
|
197
|
}
|