Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>While you need to remember that thread safety has to take into account the surrounding code as well, you appear to be in luck. The fact that <a href="http://java.sun.com/javase/6/docs/api/java/util/regex/Matcher.html" rel="nofollow noreferrer">Matchers</a> are created using the Pattern's <a href="http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html#matcher%28java.lang.CharSequence%29" rel="nofollow noreferrer">matcher</a> factory method and lack public constructors is a positive sign. Likewise, you use the <a href="http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html#compile%28java.lang.String%29" rel="nofollow noreferrer">compile</a> static method to create the encompassing <a href="http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html" rel="nofollow noreferrer">Pattern</a>.</p> <p>So, in short, if you do something like the example:</p> <pre><code>Pattern p = Pattern.compile("a*b"); Matcher m = p.matcher("aaaaab"); boolean b = m.matches(); </code></pre> <p>you should be doing pretty well.</p> <p>Follow-up to the code example for clarity: note that this example strongly implies that the Matcher thus created is thread-local with the Pattern and the test. I.e., you should not expose the Matcher thus created to any other threads.</p> <p>Frankly, that's the risk of any thread-safety question. The reality is that <strong>any</strong> code can be made thread-unsafe if you try hard enough. Fortunately, there are <a href="http://jcip.net/" rel="nofollow noreferrer">wonderful</a> <a href="http://java.sun.com/docs/books/effective/" rel="nofollow noreferrer">books</a> that teach us a whole bunch of ways that we could ruin our code. If we stay away from those mistakes, we greatly reduce our own probability of threading problems.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload