ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

具有Java过期时间的对象池的第三方库

2019-05-29 10:48:56  阅读:154  来源: 互联网

标签:java object-pooling


我在webservice服务器上,我有内部连接的对象.
初始化此连接需要很长时间,所以我的想法是使用对象池重用不同请求之间的连接.

对象连接到每个用户,因此我更喜欢使用用户名作为键,连接作为值.但我不希望永远打开这种联系.也许过了一段时间,如果用户不再启动请求,它应该被销毁.

我想过使用apache object pool,但我没有看到那里的到期(如果我错了,请纠正我)

ehcache向我提供了关于驱逐和到期的notifications,但是在超时结束后没有触发,只有在再次触摸缓存的对象时才会触发.

有人知道可以为我做这个工作的lib吗?

解决方法:

看看http://commons.apache.org/proper/commons-pool/api-1.6/org/apache/commons/pool/impl/GenericObjectPool.html

来自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,object-pooling
来源: https://codeday.me/bug/20190529/1177535.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有