xueli.xue 9 years ago
parent
commit
16cb2560b5

+ 58 - 0
xxl-job-admin/src/main/java/com/xxl/controller/IndexController.java View File

@@ -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
 }

+ 50 - 0
xxl-job-admin/src/main/java/com/xxl/quartz/ReturnT.java View File

@@ -0,0 +1,50 @@
1
+package com.xxl.quartz;
2
+
3
+/**
4
+ * common return
5
+ * @author xuxueli 2015-12-4 16:32:31
6
+ * @param <T>
7
+ */
8
+public class ReturnT<T> {
9
+	public static final ReturnT<String> SUCCESS = new ReturnT<String>(null);
10
+	public static final ReturnT<String> FAIL = new ReturnT<String>(500, null);
11
+	
12
+	private int code;
13
+	private String msg;
14
+	private T content;
15
+	
16
+	public ReturnT(int code, String msg) {
17
+		this.code = code;
18
+		this.msg = msg;
19
+	}
20
+	public ReturnT(T content) {
21
+		this.code = 200;
22
+		this.content = content;
23
+	}
24
+	
25
+	public int getCode() {
26
+		return code;
27
+	}
28
+	public void setCode(int code) {
29
+		this.code = code;
30
+	}
31
+	public String getMsg() {
32
+		return msg;
33
+	}
34
+	public void setMsg(String msg) {
35
+		this.msg = msg;
36
+	}
37
+	public T getContent() {
38
+		return content;
39
+	}
40
+	public void setContent(T content) {
41
+		this.content = content;
42
+	}
43
+
44
+	@Override
45
+	public String toString() {
46
+		return "ReturnT [code=" + code + ", msg=" + msg + ", content="
47
+				+ content + "]";
48
+	}
49
+
50
+}