You are viewing a plain text version of this content. The canonical link for it is here.
Posted to regexp-user@jakarta.apache.org by "Daniel F. Savarese" <df...@savarese.org> on 2002/03/05 02:54:58 UTC

Re: Is Util.substitute thread-safe?

In message <BE...@uspahormsx09>, Vasili Smal
>I am maintaining a servlet written by other people about a year ago. While
>processing the request, this servlet calls substitute() method of
>org.apache.oro.text.regex.Util class. In a single-user mode the substitution
>works just fine. In multi-user production mode I started noticing
>NullPointerExceptions in the log. 

First, this is the wrong mailing list.  You want oro-user.  Second,
Util.substitute() is a static method with only local state, which
means you are violating one of the following:

1. Use one PatternMatcher per thread (recommended) or synchronize access
   to it (not recommended).
2. Use one PatternCompiler per thread or synchronize access to a single
   shared instance (usually done when most or all patterns are precompiled
   and multiple pattern compilations are unlikely to occur concurrently).
2. When sharing Perl5Pattern instances between threads, compile them with
   Perl5Compiler.READ_ONLY_MASK.
3. The obvious don't use the same Substitution, PatternMatcherInput, or
   StringBuffer as method arguments at the same time.

Perl5Util is there for those unfamiliar with concurrent programming or
who just want the convenience.  The classes in org.apache.oro.text.regex
are there for those looking for performance.  It sounds like the original
authors of the code you inherited should have just used Perl5Util.
Admittedly, we need to finally write the user's guide to walk people
through the dos and don'ts of using the API and how to maximize
performance.

daniel



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>