Class TParserPool

Object
gudusoft.gsqlparser.TParserPool
Direct Known Subclasses:
TSafeParserPool

public class TParserPool extends Object
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.
  • Constructor Details

    • TParserPool

      public TParserPool()
      Creates a parser pool with default size
    • TParserPool

      public TParserPool(int poolSize)
      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

      public void returnParser(EDbVendor vendor, TGSqlParser parser)
      Returns a parser to the pool for reuse.
      Parameters:
      vendor - Database vendor
      parser - Parser instance to return
    • withParser

      public <T> T withParser(EDbVendor vendor, TParserPool.ParserFunction<T> function) throws Exception
      Executes a function with a borrowed parser and automatically returns it. This is the recommended way to use the pool.
      Parameters:
      vendor - Database vendor
      function - Function to execute with the parser
      Returns:
      Result of the function
      Throws:
      Exception
    • getStatistics

      Gets pool statistics for monitoring.
    • prewarm

      public void prewarm(EDbVendor vendor, int count)
      Pre-warms the pool by creating parsers in advance. This avoids the initialization cost during actual usage.
      Parameters:
      vendor - Database vendor
      count - Number of parsers to pre-create (up to poolSize)
    • shutdown

      public void shutdown()
      Shuts down the pool and clears all parsers.