You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oro-user@jakarta.apache.org by Kevin Stussman <ks...@westjet.com> on 2002/07/29 20:31:11 UTC

Question About Thread Safety


We have tried to use the Perl5Util class as a "thread safe" object, but are
getting odd results:

---------
import org.apache.oro.text.perl.Perl5Util;

public class MyClass
{
  protected static Perl5Util _p5u = new Perl5Util();
}
---------

then other sub-classes use the .match() and .group() methods. For example

---------
import org.apache.oro.text.perl.Perl5Util;
public class MySubClass extends MyClass
{
 private void doSomething()
 {
  if (_p5u.match("/something(.*)/"),someText)
  {
    result = _p5u.group(1)
  }
 }  
}
---------
or something like this. Anyway, in the API documentation, the class
org.apache.oro.text.perl.Perl5Util mentions:

"All the state affecting methods are synchronized to avoid the maintenance
of explicit locks in multithreaded programs. This philosophy differs from
the org.apache.oro.text.regex package, where you are expected to either
maintain explicit locks, or more preferably create separate compiler and
matcher instances for each thread."
This is a little vague to me. Does this mean we can share an object like
Perl5Util or no? Our tests seem to say no. On the surface, it looks like
.matches() from other threads are getting mixed up in .group() function
across threads....(i.e. the match result from one thread gets put into the
group call from another). This is classic non-thread safety.

Thanks for any insight. 

Kevin.


(We are using oro-2.0.5 / jdk 1.3.1_02)



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