Skip to content

Commit 6998f52

Browse files
StopWatch
1 parent f926863 commit 6998f52

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

pom.xml

+10
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
<version>2.6</version>
3535
</dependency>
3636

37+
<dependency>
38+
<groupId>org.springframework</groupId>
39+
<artifactId>spring-context</artifactId>
40+
<version>4.3.4.RELEASE</version>
41+
</dependency>
42+
3743
<dependency>
3844
<groupId>junit</groupId>
3945
<artifactId>junit</artifactId>
@@ -45,6 +51,10 @@
4551
<version>1.1.5</version>
4652
</dependency>
4753

54+
55+
56+
57+
4858
<dependency>
4959
<groupId>org.projectlombok</groupId>
5060
<artifactId>lombok</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.performance;
2+
3+
import org.springframework.util.StopWatch;
4+
5+
public class StopWatchDemo {
6+
7+
public static void main(String[] args) throws InterruptedException {
8+
stopWatch();
9+
}
10+
11+
12+
public static void stopWatch() throws InterruptedException {
13+
StopWatch stopWatch = new StopWatch("myStopWatch");
14+
15+
stopWatch.start("任务1");
16+
Thread.sleep(2000);
17+
stopWatch.stop();
18+
19+
stopWatch.start("任务2");
20+
Thread.sleep(1000);
21+
stopWatch.stop();
22+
23+
//统计耗时
24+
System.out.println(stopWatch.prettyPrint());
25+
}
26+
27+
28+
}
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.string;
2+
3+
4+
public class DeadLock {
5+
6+
private Object obj1 = new Object();
7+
private Object obj2 = new Object();
8+
9+
10+
public void lock() {
11+
new Thread( ()-> {
12+
synchronized (obj1) {
13+
try {
14+
Thread.sleep(1000);
15+
} catch (InterruptedException e) {
16+
e.printStackTrace();
17+
}
18+
19+
synchronized(obj2) {
20+
System.out.println("持有对象1,请求对象2");
21+
}
22+
23+
}
24+
25+
}).start();
26+
27+
new Thread( ()-> {
28+
synchronized (obj2) {
29+
try {
30+
Thread.sleep(1000);
31+
} catch (InterruptedException e) {
32+
e.printStackTrace();
33+
}
34+
35+
synchronized(obj1) {
36+
System.out.println("持有对象2,请求对象1");
37+
}
38+
39+
}
40+
41+
}).start();
42+
}
43+
44+
45+
46+
}

0 commit comments

Comments
 (0)