具有Java过期时间的对象池的第三方库
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了具有Java过期时间的对象池的第三方库,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1585字,纯文字阅读大概需要3分钟。
内容图文
![具有Java过期时间的对象池的第三方库](/upload/InfoBanner/zyjiaocheng/817/a9668c7043954e24b72935a9559c5251.jpg)
我在webservice服务器上,我有内部连接的对象.
初始化此连接需要很长时间,所以我的想法是使用对象池重用不同请求之间的连接.
对象连接到每个用户,因此我更喜欢使用用户名作为键,连接作为值.但我不希望永远打开这种联系.也许过了一段时间,如果用户不再启动请求,它应该被销毁.
我想过使用apache object pool,但我没有看到那里的到期(如果我错了,请纠正我)
ehcache向我提供了关于驱逐和到期的notifications,但是在超时结束后没有触发,只有在再次触摸缓存的对象时才会触发.
有人知道可以为我做这个工作的lib吗?
解决方法:
来自javadoc:
Optionally, one may configure the pool to examine and possibly evict objects
as they sit idle in the pool and to ensure that a minimum number of idle
objects are available. This is performed by an "idle object eviction" thread,
which runs asynchronously. Caution should be used when configuring this
optional feature. Eviction runs contend with client threads for access to
objects in the pool, so if they run too frequently performance issues may
result.
....
minEvictableIdleTimeMillis specifies the minimum amount of time that
an object may sit idle in the pool before it is eligible for eviction
due to idle time. When non-positive, no object will be dropped from
the pool due to idle time alone. This setting has no effect unless
timeBetweenEvictionRunsMillis > 0. The default setting for this
parameter is 30 minutes.
实现一个PoolableObjectFactory来创建你的连接,并实现PoolableObjectFactory.destroyObject(T object)方法来关闭你的连接.当对象被驱逐时,GenericObejctPool将调用此方法.
内容总结
以上是互联网集市为您收集整理的具有Java过期时间的对象池的第三方库全部内容,希望文章能够帮你解决具有Java过期时间的对象池的第三方库所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。