Similar to Is Java Regex Thread Safe?, I would like to know if this usage of scala regex is really thread safe? Are multiple threads able to call m on the same object M without interfering with each other in the result?
object R {
val pat = """a(\d)""".r
}
class M {
def m(s: String): Option[Int] = {
s match {
case R.pat(i) => Some(i.toInt)
case _ => None
}
}
}
There are more than one class. It breaks down to:
scala.util.matching.Regex
depends on java.util.regex.Pattern
, so, according to JavaDoc, thread-safe.scala.util.matching.Regex.Match
depends on java.util.regex.Match
, so, according to JavaDoc, not thread-safe.scala.util.matching.Regex.MatchIterator
is mutable, and contains java.util.regex.Match
, so not thread-safe.scala.util.matching.Regex.MatchData
is technically thread-safe, but it only appears as part of the two classes above, so you won't find thread-safe instances of MatchData
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With