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 "Sharpe, Cassandra" <ca...@merck.com> on 2001/10/16 18:41:35 UTC

Question about Patterns and Thread Safety

Hello,

I have an application that transforms HTML documents at run time using the
Jakarta ORO library.  I have created a number of Perl5Patterns and I would
like to place them in a singleton class and have all threads share these
patterns rather than compile them every time an html file is requested from
the web server.  

Is it safe/recommended to place patterns in a singleton and use the
Perl5Compiler.READ_ONLY_MASK?

The singleton class would behave as follows.....

class PatternSingleton {

 private Pattern htmlPattern ;
  
 private PatternSingleton ( ) {

   PatternCompiler compiler = new Perl5Compiler();

   htmlPattern = compiler.compile( someExpression,
Perl5Compiler.READ_ONLY_MASK);
   
 }

//.... OTHER methods here

 public Pattern getPattern ( ) { return htmlPattern; }

}

Thank You,

Cassandra