File tree 1 file changed +14
-4
lines changed
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/system
1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2012-2022 the original author or authors.
2
+ * Copyright 2012-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
28
28
import java .security .MessageDigest ;
29
29
import java .util .EnumSet ;
30
30
import java .util .HexFormat ;
31
+ import java .util .concurrent .locks .Lock ;
32
+ import java .util .concurrent .locks .ReentrantLock ;
31
33
32
34
import org .springframework .util .Assert ;
33
35
import org .springframework .util .StringUtils ;
@@ -49,6 +51,8 @@ public class ApplicationTemp {
49
51
50
52
private final Class <?> sourceClass ;
51
53
54
+ private final Lock pathLock = new ReentrantLock ();
55
+
52
56
private volatile Path path ;
53
57
54
58
/**
@@ -90,9 +94,15 @@ public File getDir(String subDir) {
90
94
91
95
private Path getPath () {
92
96
if (this .path == null ) {
93
- synchronized (this ) {
94
- String hash = HexFormat .of ().withUpperCase ().formatHex (generateHash (this .sourceClass ));
95
- this .path = createDirectory (getTempDirectory ().resolve (hash ));
97
+ this .pathLock .lock ();
98
+ try {
99
+ if (this .path == null ) {
100
+ String hash = HexFormat .of ().withUpperCase ().formatHex (generateHash (this .sourceClass ));
101
+ this .path = createDirectory (getTempDirectory ().resolve (hash ));
102
+ }
103
+ }
104
+ finally {
105
+ this .pathLock .unlock ();
96
106
}
97
107
}
98
108
return this .path ;
You can’t perform that action at this time.
0 commit comments