博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java 池技术 - commons-pool
阅读量:5947 次
发布时间:2019-06-19

本文共 4892 字,大约阅读时间需要 16 分钟。

hot3.png

public interface ObjectPool
{ /** * 从对象池中获取到一个对象。 * * 该对象可以是通过 PoolableObjectFactory 的 makeObject方法 创建, * 也可以是之前创建的,现在处于闲置状态的对象。而且该对象还通过了 PoolableObjectFactory * 的activateObject激活和validateObject方法的校验 * * 这里约定,客户端归还借的对象必须使用 returnObject invalidateObject,或者是子类中 * 定义的一个相关的方法 * * 当对象池的资源耗尽的时候(对象借光啦),这个方法并没有严格的规定其行为。老的版本中会返回null 新的版本中鼓励抛出NoSuchElementException异常 */ T borrowObject() throws Exception, NoSuchElementException, IllegalStateException; /** * Return an instance to the pool. * By contract,
obj
must have been obtained * using {@link #borrowObject() borrowObject} * or a related method as defined in an implementation * or sub-interface. * * @param obj a {@link #borrowObject borrowed} instance to be returned. * @throws Exception */ void returnObject(T obj) throws Exception; /** *

Invalidates an object from the pool.

* *

By contract, obj must have been obtained * using {@link #borrowObject borrowObject} or a related method as defined in * an implementation or sub-interface.

* *

This method should be used when an object that has been borrowed * is determined (due to an exception or other problem) to be invalid.

* * @param obj a {@link #borrowObject borrowed} instance to be disposed. * @throws Exception */ void invalidateObject(T obj) throws Exception; /** * Create an object using the {@link PoolableObjectFactory factory} or other * implementation dependent mechanism, passivate it, and then place it in the idle object pool. *
addObject is useful for "pre-loading" a pool with idle objects. * (Optional operation). * * @throws Exception when {@link PoolableObjectFactory#makeObject} fails. * @throws IllegalStateException after {@link #close} has been called on this pool. * @throws UnsupportedOperationException when this pool cannot add new idle objects. */ void addObject() throws Exception, IllegalStateException, UnsupportedOperationException; /** * Return the number of instances * currently idle in this pool (optional operation). * This may be considered an approximation of the number * of objects that can be {@link #borrowObject borrowed} * without creating any new instances. * Returns a negative value if this information is not available. * * @return the number of instances currently idle in this pool or a negative value if unsupported * @throws UnsupportedOperationException
deprecated: if this implementation does not support the operation */ int getNumIdle() throws UnsupportedOperationException; /** * Return the number of instances * currently borrowed from this pool * (optional operation). * Returns a negative value if this information is not available. * * @return the number of instances currently borrowed from this pool or a negative value if unsupported * @throws UnsupportedOperationException
deprecated: if this implementation does not support the operation */ int getNumActive() throws UnsupportedOperationException; /** * Clears any objects sitting idle in the pool, releasing any * associated resources (optional operation). * Idle objects cleared must be {@link PoolableObjectFactory#destroyObject(Object) destroyed}. * * @throws UnsupportedOperationException if this implementation does not support the operation */ void clear() throws Exception, UnsupportedOperationException; /** * Close this pool, and free any resources associated with it. *

* Calling {@link #addObject} or {@link #borrowObject} after invoking * this method on a pool will cause them to throw an * {@link IllegalStateException}. *

* * @throws Exception
deprecated: implementations should silently fail if not all resources can be freed. */ void close() throws Exception; /** * Sets the {@link PoolableObjectFactory factory} this pool uses * to create new instances (optional operation). Trying to change * the
factory after a pool has been used will frequently * throw an {@link UnsupportedOperationException}. It is up to the pool * implementation to determine when it is acceptable to call this method. * * @param factory the {@link PoolableObjectFactory} used to create new instances. * @throws IllegalStateException when the factory cannot be set at this time * @throws UnsupportedOperationException if this implementation does not support the operation * @deprecated to be removed in pool 2.0 */ @Deprecated void setFactory(PoolableObjectFactory
factory) throws IllegalStateException, UnsupportedOperationException;}

 

转载于:https://my.oschina.net/u/206123/blog/1560781

你可能感兴趣的文章
度量时间差
查看>>
通过jsp请求Servlet来操作HBASE
查看>>
crontab执行shell脚本日志中出现乱码
查看>>
Shell编程基础
查看>>
Shell之Sed常用用法
查看>>
3.1
查看>>
校验表单如何摆脱 if else ?
查看>>
JS敏感信息泄露:不容忽视的WEB漏洞
查看>>
分布式memcached服务器代理magent安装配置(CentOS6.6)
查看>>
Create Volume 操作(Part III) - 每天5分钟玩转 OpenStack(52)
查看>>
tomcat 8.0虚拟机配置文档
查看>>
pxc群集搭建
查看>>
JS中加载cssText延时
查看>>
常用的脚本编程知识点
查看>>
计算机网络术语总结4
查看>>
新手小白 python之路 Day3 (string 常用方法)
查看>>
soapUI的简单使用(webservice接口功能测试)
查看>>
框架 Hibernate
查看>>
python-while循环
查看>>
手机端上传图片及java后台接收和ajaxForm提交
查看>>