jakarta-regexp-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 34548] - RE constructor is not thread safe
Date Fri, 22 Apr 2005 06:12:36 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=34548>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=34548





------- Additional Comments From james.cherryh@defence.gov.au  2005-04-22 08:12 -------
So something like this perhaps. We create a new class REThreadsafe (code below)
which wraps the RE constructor in a synchronized block. We create an interface
REInterface (code below) for the public methods on RE and REThreadsafe to ensure
that they stay in step.

The naive user can then create and use a new REThreadsafe just like they use an
RE instance. Existing users of RE are not affected or impacted.

REThreadsafe 
============

package org.apache.regexp;

public class REThreadsafe implements REInterface {

  final RE wrappedRE;


  public REThreadsafe(REProgram program, int matchFlags) {

     synchronized (REThreadsafe.class) {
        wrappedRE = new RE(program, matchFlags);
     }
   }


   public REThreadsafe(REProgram program) {
       this(program, RE.MATCH_NORMAL);
   }


   public REThreadsafe() {
       this((REProgram)null, RE.MATCH_NORMAL);
   }


   public REThreadsafe(String pattern) throws RESyntaxException {
       this(pattern, RE.MATCH_NORMAL);
   }


   public REThreadsafe(String pattern, int matchFlags) throws RESyntaxException {
       this(new RECompiler().compile(pattern));
       setMatchFlags(matchFlags);
   }


  public REProgram getProgram() {
    return wrappedRE.getProgram();
  }
  public String getParen(int which) {
    return wrappedRE.getParen(which);
  }
  public void setMatchFlags(int matchFlags) {
    wrappedRE.setMatchFlags(matchFlags);
  }
  public String[] split(String s) {
    return wrappedRE.split(s);
  }
  public boolean match(String search) {
    return wrappedRE.match(search);
  }
  public String subst(String substituteIn, String substitution) {
    return wrappedRE.subst(substituteIn, substitution);
  }
  public boolean match(CharacterIterator parm1, int parm2) {
    return wrappedRE.match(parm1, parm2);
  }
  public String[] grep(Object[] parm1) {
    return wrappedRE.grep(parm1);
  }
  public int getParenCount() {
    return wrappedRE.getParenCount();
  }
  public boolean match(String search, int i) {
    return wrappedRE.match(search, i);
  }
  public String subst(String substituteIn, String substitution, int flags) {
    return wrappedRE.subst(substituteIn, substitution, flags);
  }
  public void setProgram(REProgram parm1) {
    wrappedRE.setProgram(parm1);
  }
  public int getMatchFlags() {
    return wrappedRE.getMatchFlags();
  }


}



REInterface
===========

package org.apache.regexp;

interface REInterface {

  REProgram getProgram();

  String getParen(int which);

  void setMatchFlags(int matchFlags);

  String[] split(String s);

  boolean match(String search);

  String subst(String substituteIn, String substitution);

  boolean match(CharacterIterator parm1, int parm2);

  String[] grep(Object[] parm1);

  int getParenCount();

  boolean match(String search, int i);

  String subst(String substituteIn, String substitution, int flags);

  void setProgram(REProgram parm1);

}


-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: regexp-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: regexp-dev-help@jakarta.apache.org


Mime
View raw message