Thread Safety

Mathias edited this page Jan 26, 2011 · 4 revisions
Clone this wiki locally

Parser (parboiled for Java)

The parser classes created by parboiled for Java are not thread-safe. This means you have to create a separate parser instance for each thread you would like to run your parser concurrently from. However, once parboiled has extended your parser class during the initial call to Parboiled.createParser all further parser object instantiations are fast. If your application needs to regularly create a lot of parser instances you should also consider using the BaseParser.newInstance call for creating your parsers. Since this call does not use reflection for object creation it is significantly faster than Parboiled.createParser.

Rule Tree

Since the rule tree does not hold any state during rule execution it should be concurrently usable by multiple parser instances from multiple threads, once you have a rule tree built and the root rule properly created.

ParseRunners

Similar to the parser itself the ParseRunner implementations provided by parboiled are not threadsafe. This means that you should not use the same instance concurrently from multiple threads without synchronization. However, since ParseRunners are lightweight you can just create new instances for every parse (which is exactly what the static run(…) methods (like ReportingParseRunner.run) do).