Here is the patch suggested by Andrea to just cache the compiled the pattern (which is thread safe) rather than the matcher (which is not thread safe).
Justin Deoliveira
added a comment - Here is the patch suggested by Andrea to just cache the compiled the pattern (which is thread safe) rather than the matcher (which is not thread safe).
Looking at it you could avoid resetting the matcher if getMatcher() takes the target strings as a param. Usually the pattern to match a string is pattern.matcher(string).matches().
Or else change the method into getPattern() and apply the matcher outside (would look better, separate the cached part from the non cached one).
Minor thing anyways
Andrea Aime
added a comment - Looking at it you could avoid resetting the matcher if getMatcher() takes the target strings as a param. Usually the pattern to match a string is pattern.matcher(string).matches().
Or else change the method into getPattern() and apply the matcher outside (would look better, separate the cached part from the non cached one).
Minor thing anyways
Justin Deoliveira
added a comment - Ahh right, the reset is pointless, good catch, i was just doing the bare minimum to avoid the race condition. Thanks for the review.