public class CachingParserPool extends Object
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.
Modifier and Type | Class and Description |
---|---|
static class |
CachingParserPool.ShadowedGrammarPool
Shadowed grammar pool.
|
static class |
CachingParserPool.SynchronizedGrammarPool
Synchronized grammar pool.
|
Modifier and Type | Field and Description |
---|---|
static boolean |
DEFAULT_SHADOW_GRAMMAR_POOL
Default shadow grammar pool (false).
|
static boolean |
DEFAULT_SHADOW_SYMBOL_TABLE
Default shadow symbol table (false).
|
protected boolean |
fShadowGrammarPool
Shadow the grammar pool for new parser instances.
|
protected boolean |
fShadowSymbolTable
Shadow the symbol table for new parser instances.
|
protected XMLGrammarPool |
fSynchronizedGrammarPool
Grammar pool.
|
protected SymbolTable |
fSynchronizedSymbolTable
Symbol table.
|
Constructor and Description |
---|
CachingParserPool()
Default constructor.
|
CachingParserPool(SymbolTable symbolTable,
XMLGrammarPool grammarPool)
Constructs a caching parser pool with the specified symbol table
and grammar pool.
|
Modifier and Type | Method and Description |
---|---|
DOMParser |
createDOMParser()
Creates a new DOM parser.
|
SAXParser |
createSAXParser()
Creates a new SAX parser.
|
SymbolTable |
getSymbolTable()
Returns the symbol table.
|
XMLGrammarPool |
getXMLGrammarPool()
Returns the grammar pool.
|
void |
setShadowSymbolTable(boolean shadow)
Sets whether new parser instance receive shadow copies of the
main symbol table.
|
public static final boolean DEFAULT_SHADOW_SYMBOL_TABLE
public static final boolean DEFAULT_SHADOW_GRAMMAR_POOL
protected SymbolTable fSynchronizedSymbolTable
protected XMLGrammarPool fSynchronizedGrammarPool
protected boolean fShadowSymbolTable
protected boolean fShadowGrammarPool
public CachingParserPool()
public CachingParserPool(SymbolTable symbolTable, XMLGrammarPool grammarPool)
symbolTable
- The symbol table.grammarPool
- The grammar pool.public SymbolTable getSymbolTable()
public XMLGrammarPool getXMLGrammarPool()
public void setShadowSymbolTable(boolean shadow)
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.public DOMParser createDOMParser()
public SAXParser createSAXParser()
Copyright © 2018 JBoss by Red Hat. All rights reserved.