Class CachingParserPool
Once the caching parser pool is constructed, specific parser instances are created by calling the appropriate factory method on the parser pool.
Note: There is a performance penalty for using a caching parser pool due to thread safety. Access to the symbol table and grammar pool must be synchronized to ensure the safe operation of the symbol table and grammar pool.
Note: If performance is critical, then another mechanism needs to be used instead of the caching parser pool. One approach would be to create parser instances that do not share these structures. Instead, each instance would get its own copy to use while parsing. This avoids the synchronization overhead at the expense of more memory and the time required to copy the structures for each new parser instance. And even when a parser instance is re-used, there is a potential for a memory leak due to new symbols being added to the symbol table over time. In other words, always take caution to make sure that your application is thread-safe and avoids leaking memory.
- Version:
- $Id: CachingParserPool.java 699892 2008-09-28 21:08:27Z mrglavas $
- Author:
- Andy Clark, IBM
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Shadowed grammar pool.static final class
Synchronized grammar pool. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final boolean
Default shadow grammar pool (false).static final boolean
Default shadow symbol table (false).protected boolean
Shadow the grammar pool for new parser instances.protected boolean
Shadow the symbol table for new parser instances.protected org.apache.xerces.xni.grammars.XMLGrammarPool
Grammar pool.protected SymbolTable
Symbol table. -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.CachingParserPool
(SymbolTable symbolTable, org.apache.xerces.xni.grammars.XMLGrammarPool grammarPool) Constructs a caching parser pool with the specified symbol table and grammar pool. -
Method Summary
Modifier and TypeMethodDescriptionCreates a new DOM parser.Creates a new SAX parser.Returns the symbol table.org.apache.xerces.xni.grammars.XMLGrammarPool
Returns the grammar pool.void
setShadowSymbolTable
(boolean shadow) Sets whether new parser instance receive shadow copies of the main symbol table.
-
Field Details
-
DEFAULT_SHADOW_SYMBOL_TABLE
public static final boolean DEFAULT_SHADOW_SYMBOL_TABLEDefault shadow symbol table (false).- See Also:
-
DEFAULT_SHADOW_GRAMMAR_POOL
public static final boolean DEFAULT_SHADOW_GRAMMAR_POOLDefault shadow grammar pool (false).- See Also:
-
fSynchronizedSymbolTable
Symbol table. The symbol table that the caching parser pool is constructed with is automatically wrapped in a synchronized version for thread-safety. -
fSynchronizedGrammarPool
protected org.apache.xerces.xni.grammars.XMLGrammarPool fSynchronizedGrammarPoolGrammar pool. The grammar pool that the caching parser pool is constructed with is automatically wrapped in a synchronized version for thread-safety. -
fShadowSymbolTable
protected boolean fShadowSymbolTableShadow the symbol table for new parser instances. If true, new parser instances use shadow copies of the main symbol table and are not allowed to add new symbols to the main symbol table. New symbols are added to the shadow symbol table and are local to the parser instance. -
fShadowGrammarPool
protected boolean fShadowGrammarPoolShadow the grammar pool for new parser instances. If true, new parser instances use shadow copies of the main grammar pool and are not allowed to add new grammars to the main grammar pool. New grammars are added to the shadow grammar pool and are local to the parser instance.
-
-
Constructor Details
-
CachingParserPool
public CachingParserPool()Default constructor. -
CachingParserPool
public CachingParserPool(SymbolTable symbolTable, org.apache.xerces.xni.grammars.XMLGrammarPool grammarPool) Constructs a caching parser pool with the specified symbol table and grammar pool.- Parameters:
symbolTable
- The symbol table.grammarPool
- The grammar pool.
-
-
Method Details
-
getSymbolTable
Returns the symbol table. -
getXMLGrammarPool
public org.apache.xerces.xni.grammars.XMLGrammarPool getXMLGrammarPool()Returns the grammar pool. -
setShadowSymbolTable
public void setShadowSymbolTable(boolean shadow) Sets whether new parser instance receive shadow copies of the main symbol table.- Parameters:
shadow
- If true, new parser instances use shadow copies of the main symbol table and are not allowed to add new symbols to the main symbol table. New symbols are added to the shadow symbol table and are local to the parser instance. If false, new parser instances are allowed to add new symbols to the main symbol table.
-
createDOMParser
Creates a new DOM parser. -
createSAXParser
Creates a new SAX parser.
-