Are parsers generated by ANTLR thread-safe? Can I parse multiple inputs concurrently?
Location: http://www.jguru.com/faq/view.jsp?EID=93725 Created: Jul 2, 2000 Modified: 2000-07-02 13:15:41.765 Author: Terence Parr (http://www.jguru.com/guru/viewbio.jsp?EID=1) Question originally posed by Alexis Campailla (http://www.jguru.com/guru/viewbio.jsp?EID=5326 The simple answer is “yes”, however, if you try to parse the same input using the same object with more than one thread the answer is “no”. Fortunately, parsing is, for the most part, an inherently serial problem so you’d never want multiple threads playing with the same input stream object. Typically this question is really asking, “can I make multiple instances of the same parser and parse multiple input streams at the same time?” Emphatically, “yes”. There are not global variables or shared static variables that would force all parsers to operate at different times. You can have multiple parsers and multiple lexers all operating on the same input stream (to handle complicated input streams like java/javadoc comments),