Search code examples
javaobject-poolingapache-commons-pool

Object pool with the ability save objects on exit and reload on start?


Apache Commons seems to be the decent Object Pool implementation out there. Or any other framework that could support the cause

How Can I save its state of the pool during shutdown; may be serialize its objects to a external form json, xml ..? and reload during next startup ?


Solution

  • It is possible to capture objects in a pool when the pool is closed and put these objects back in the pool when a pool is opened with Yapool. I added a test-case to Yapool that shows how this could be done.

    Persisting these objects "between pools" is not part of Yapool. But you can, for example, store them in a file and load them before a pool is opened.

    Update: added another test-case which shows a more proper implementation and also shows a corner-case.