How to return objects to the Pool by timeout using apache commons pool

梦想的初衷 提交于 2019-12-04 08:59:42

Assuming that the destroy / create new approach is OK and you are using version 2.0+ of commons pool, you can use abandoned object tracking and removal to make sure capacity is not permanently leaked when objects are borrowed and never returned. See the javadoc for AbandonedConfig for the configuration settings and the GenericObjectPool constructor that takes an AbandonedConfig instance as an argument. With abandoned object tracking and removal enabled, the pool will destroy instances that have been borrowed but not returned for longer than the removeAbandonedTimeout when the pool is low on capacity.

If for some reason you have to use a version 1.x pool, you can grab the source or use directly the AbandonedObjectPool that ships with DBCP 1.x.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!