forked from janzolau1987/study-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfiler.java
More file actions
31 lines (26 loc) · 761 Bytes
/
Profiler.java
File metadata and controls
31 lines (26 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.yaoyaohao.study.thread;
import java.util.concurrent.TimeUnit;
/**
* ThreadLocal的使用
*
* @author liujianzhu
* @date 2016年7月22日 下午3:24:14
*/
public class Profiler {
private static final ThreadLocal<Long> TIME_THREADLOCAL = new ThreadLocal<Long>() {
protected Long initialValue() {
return System.currentTimeMillis();
}
};
public static final void begin() {
TIME_THREADLOCAL.set(System.currentTimeMillis());
}
public static final long end() {
return System.currentTimeMillis() - TIME_THREADLOCAL.get();
}
public static void main(String[] args) throws Exception {
Profiler.begin();
TimeUnit.SECONDS.sleep(5);
System.out.println("Cost " + Profiler.end() + " mills");
}
}