This was an improvement to GlassFish's RubyObjectPool that Jeanfrancois
Arcand mentioned the Grizzly community might be interested in
integrating directly into Grizzly. It is a pool object that will support
arbitrary object types and will resize itself based on load to avoid
long service times or excessive idle pool objects.
The original goal for this code was to allow GlassFish to quickly
support many scripting languages using the same underlying pooling
logic, to increase the speed at which new languages could be added and
reduce the maintenance required.
Some caveats:
1) The code tries hard to be thread-safe, but I'm not experienced enough
with multithreaded programming to prove that it is. Just something to be
aware of and/or test for.
2) The trimming (and growing) behavior is triggered through objects
being returned or borrowed from the pool, so a pool experiencing zero
load will not shrink. This was a simplifying assumption made when it was
only pooling runtimes, so it may require some small amount of
modification if it is to be used for something that isn't constantly
under some small amount of load.