17
17
package org .springframework .web .util ;
18
18
19
19
import java .util .Comparator ;
20
- import java .util .HashMap ;
21
20
import java .util .Map ;
21
+ import java .util .concurrent .ConcurrentHashMap ;
22
+ import java .util .concurrent .ConcurrentMap ;
22
23
23
24
import org .springframework .util .PathMatcher ;
24
25
import org .springframework .web .util .patterns .PathPattern ;
39
40
*/
40
41
public class ParsingPathMatcher implements PathMatcher {
41
42
42
- Map <String , PathPattern > cache = new HashMap <>();
43
+ private final ConcurrentMap <String , PathPattern > cache =
44
+ new ConcurrentHashMap <>(64 );
43
45
44
- PathPatternParser parser ;
45
-
46
- public ParsingPathMatcher () {
47
- parser = new PathPatternParser ();
48
- }
46
+ private static final ThreadLocal <PathPatternParser > PARSER
47
+ = ThreadLocal .withInitial (() -> new PathPatternParser ());
49
48
50
49
@ Override
51
50
public boolean match (String pattern , String path ) {
@@ -84,10 +83,10 @@ public Comparator<String> getPatternComparator(String path) {
84
83
85
84
class PathPatternStringComparatorConsideringPath implements Comparator <String > {
86
85
87
- PatternComparatorConsideringPath ppcp ;
86
+ private final PatternComparatorConsideringPath ppcp ;
88
87
89
88
public PathPatternStringComparatorConsideringPath (String path ) {
90
- ppcp = new PatternComparatorConsideringPath (path );
89
+ this . ppcp = new PatternComparatorConsideringPath (path );
91
90
}
92
91
93
92
@ Override
@@ -100,7 +99,7 @@ else if (o2 == null) {
100
99
}
101
100
PathPattern p1 = getPathPattern (o1 );
102
101
PathPattern p2 = getPathPattern (o2 );
103
- return ppcp .compare (p1 , p2 );
102
+ return this . ppcp .compare (p1 , p2 );
104
103
}
105
104
106
105
}
@@ -112,10 +111,10 @@ public boolean isPattern(String path) {
112
111
}
113
112
114
113
private PathPattern getPathPattern (String pattern ) {
115
- PathPattern pathPattern = cache .get (pattern );
114
+ PathPattern pathPattern = this . cache .get (pattern );
116
115
if (pathPattern == null ) {
117
- pathPattern = parser .parse (pattern );
118
- cache .put (pattern , pathPattern );
116
+ pathPattern = PARSER . get () .parse (pattern );
117
+ this . cache .put (pattern , pathPattern );
119
118
}
120
119
return pathPattern ;
121
120
}
0 commit comments