Browse Source

Revert ParsingPathMatcher concurrency checks

`PathPatternParser` is now thread-safe and creates a new internal parser
for each `parse` call, since this operation is cheap.
This commit removes the `ThreadLocal` based instances of
`PathPatternParser` in `ParsingPathMatcher` which are not required
anymore.

Issue: SPR-15246
pull/1334/head
Brian Clozel 8 years ago
parent
commit
babd5517aa
  1. 5
      spring-web/src/main/java/org/springframework/web/util/ParsingPathMatcher.java
  2. 4
      spring-web/src/main/java/org/springframework/web/util/patterns/PathPatternParser.java

5
spring-web/src/main/java/org/springframework/web/util/ParsingPathMatcher.java

@ -43,8 +43,7 @@ public class ParsingPathMatcher implements PathMatcher { @@ -43,8 +43,7 @@ public class ParsingPathMatcher implements PathMatcher {
private final ConcurrentMap<String, PathPattern> cache =
new ConcurrentHashMap<>(64);
private static final ThreadLocal<PathPatternParser> PARSER
= ThreadLocal.withInitial(() -> new PathPatternParser());
private final PathPatternParser parser = new PathPatternParser();
@Override
public boolean match(String pattern, String path) {
@ -113,7 +112,7 @@ public class ParsingPathMatcher implements PathMatcher { @@ -113,7 +112,7 @@ public class ParsingPathMatcher implements PathMatcher {
private PathPattern getPathPattern(String pattern) {
PathPattern pathPattern = this.cache.get(pattern);
if (pathPattern == null) {
pathPattern = PARSER.get().parse(pattern);
pathPattern = this.parser.parse(pattern);
this.cache.put(pattern, pathPattern);
}
return pathPattern;

4
spring-web/src/main/java/org/springframework/web/util/patterns/PathPatternParser.java

@ -63,9 +63,9 @@ public class PathPatternParser { @@ -63,9 +63,9 @@ public class PathPatternParser {
* @param pathPattern the input path pattern, e.g. /foo/{bar}
* @return a PathPattern for quickly matching paths against the specified path pattern
*/
public PathPattern parse(String pattern) {
public PathPattern parse(String pathPattern) {
InternalPathPatternParser ippp = new InternalPathPatternParser(separator, caseSensitive);
return ippp.parse(pattern);
return ippp.parse(pathPattern);
}
}

Loading…
Cancel
Save