File tree 3 files changed +84
-0
lines changed
main/java/com/performance
3 files changed +84
-0
lines changed Original file line number Diff line number Diff line change 34
34
<version >2.6</version >
35
35
</dependency >
36
36
37
+ <dependency >
38
+ <groupId >org.springframework</groupId >
39
+ <artifactId >spring-context</artifactId >
40
+ <version >4.3.4.RELEASE</version >
41
+ </dependency >
42
+
37
43
<dependency >
38
44
<groupId >junit</groupId >
39
45
<artifactId >junit</artifactId >
45
51
<version >1.1.5</version >
46
52
</dependency >
47
53
54
+
55
+
56
+
57
+
48
58
<dependency >
49
59
<groupId >org.projectlombok</groupId >
50
60
<artifactId >lombok</artifactId >
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments