> private static final Perl5Matcher MATCHER = new Perl5Matcher();
>
[quoted text clipped - 13 lines]
> see anything in the docs to say either way, but I am a bit paranoid
> since matches isn't a static call..
Looks fine to me. I don't know what Pel5Matcher is.
java.util.regex.Matcher is not thread-safe, so requires the synchronized
block.
You can write the method body more simple as:
synchronized (MATCHER) {
return MATCHER.matches(field, regex);
}
If it is a frequently used method on a multiprocessor machine (even
desktops have multiple hardware threads these days), it may be worth
having a separate matcher for each thread:
private static final ThreadLocal<Perl5Matcher> MATCHER =
new ThreadLocal<Perl5Matcher>() {
@Override
protected Perl5Matcher initialValue() {
return new Perl5Matcher();
}
};
private static boolean validateRegex(
final String field, final Pattern regex
) {
return MATCHER.get().matches(field, regex);
}
(Usual warning that you wont get class unloading with this sort of use
of ThreadLocal: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6254531)
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/