Uploaded image for project: 'Velocity'
  1. Velocity
  2. VELOCITY-434

Commons pool implementation of the parser pool

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Won't Fix
    • None
    • None
    • Engine
    • None

    Description

      Now that with [Velocity-433] we can swap out the parser pool, here is a parser pool that uses commons-pool (http://jakarta.apache.org/commons/pool/).

      It is very primitive configuration and uses the same configuration name (parser.pool.size) for maximum number of elements in the pool. It is also configured to grow when the maximum number is exhausted, which means that it scales the same way as the original parser, while actually providing some better pool support.

      One of the nicest parts about this is that you can set your maximum instances to 0 and still get great performance. The first time you need a parser, it will still add one even though the max is reached (since grow when exhausted is set). Assuming the second time you need a parser is within a few seconds, that first instance is still there.

      Here is some sample code of how to use it your app.

      Properties configuration = new Properties();
      configuration.put("parser.pool.class", "com.lokitech.util.pool.CommonsParserPool");
      configuration.put("parser.pool.size", "0");
      Velocity.init(configuration);

      Since Velocity does not have an existing dependency on commons pool, I'm not sure this code will get packaged into the main distribution. This code is licensed using ASL 2.0, so please reuse however you want as long as attribution is kept per the license.

      Attachments

        1. CommonsParserPool.java
          1 kB
          Serge Knystautas
        2. CommonsParserPool.java
          1 kB
          Serge Knystautas
        3. CommonsParserPoolFactory.java
          1 kB
          Serge Knystautas

        Issue Links

          Activity

            People

              Unassigned Unassigned
              serge Serge Knystautas
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: