Package gudusoft.gsqlparser
Class TParserPool
Object
gudusoft.gsqlparser.TParserPool
- Direct Known Subclasses:
TSafeParserPool
Thread-safe parser pool implementation to replace the singleton pattern.
This pool dramatically improves performance in multi-threaded environments
by eliminating synchronized method bottlenecks.
Each database vendor has its own pool of parser instances that can be
borrowed and returned for reuse.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface for parser operations.static classPool statistics for monitoring.static classCustom exception for timeout scenarios. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a parser pool with default sizeTParserPool(int poolSize) Creates a parser pool with specified size -
Method Summary
Modifier and TypeMethodDescriptionborrowParser(EDbVendor vendor) Borrows a parser from the pool for the specified vendor.getStatistics(EDbVendor vendor) Gets pool statistics for monitoring.voidPre-warms the pool by creating parsers in advance.voidreturnParser(EDbVendor vendor, TGSqlParser parser) Returns a parser to the pool for reuse.voidshutdown()Shuts down the pool and clears all parsers.<T> TwithParser(EDbVendor vendor, TParserPool.ParserFunction<T> function) Executes a function with a borrowed parser and automatically returns it.
-
Constructor Details
-
TParserPool
public TParserPool()Creates a parser pool with default size -
TParserPool
Creates a parser pool with specified size- Parameters:
poolSize- Size of the pool for each vendor
-
-
Method Details
-
borrowParser
Borrows a parser from the pool for the specified vendor. If no parser is available, creates a new one up to the pool limit.- Parameters:
vendor- Database vendor- Returns:
- Parser instance
- Throws:
InterruptedException- if interrupted while waiting
-
returnParser
Returns a parser to the pool for reuse.- Parameters:
vendor- Database vendorparser- Parser instance to return
-
withParser
Executes a function with a borrowed parser and automatically returns it. This is the recommended way to use the pool.- Parameters:
vendor- Database vendorfunction- Function to execute with the parser- Returns:
- Result of the function
- Throws:
Exception
-
getStatistics
Gets pool statistics for monitoring. -
prewarm
Pre-warms the pool by creating parsers in advance. This avoids the initialization cost during actual usage.- Parameters:
vendor- Database vendorcount- Number of parsers to pre-create (up to poolSize)
-
shutdown
Shuts down the pool and clears all parsers.
-