File tree Expand file tree Collapse file tree 3 files changed +84
-0
lines changed
main/java/com/performance Expand file tree Collapse file tree 3 files changed +84
-0
lines changed Original file line number Diff line number Diff line change 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 >
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 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