📄 genericobjectpool.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc (build 1.5.0_06) on Sun Apr 02 20:52:30 EDT 2006 --><META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><TITLE>GenericObjectPool (Commons Pool 1.3 API)</TITLE><META NAME="keywords" CONTENT="org.apache.commons.pool.impl.GenericObjectPool class"><LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../../stylesheet.css" TITLE="Style"><SCRIPT type="text/javascript">function windowTitle(){ parent.document.title="GenericObjectPool (Commons Pool 1.3 API)";}</SCRIPT><NOSCRIPT></NOSCRIPT></HEAD><BODY BGCOLOR="white" onload="windowTitle();"><!-- ========= START OF TOP NAVBAR ======= --><A NAME="navbar_top"><!-- --></A><A HREF="#skip-navbar_top" title="Skip navigation links"></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY=""> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/GenericObjectPool.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../../../../org/apache/commons/pool/impl/GenericKeyedObjectPoolFactory.html" title="class in org.apache.commons.pool.impl"><B>PREV CLASS</B></A> <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.Config.html" title="class in org.apache.commons.pool.impl"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../../../../index.html?org/apache/commons/pool/impl/GenericObjectPool.html" target="_top"><B>FRAMES</B></A> <A HREF="GenericObjectPool.html" target="_top"><B>NO FRAMES</B></A> <SCRIPT type="text/javascript"> <!-- if(window==top) { document.writeln('<A HREF="../../../../../allclasses-noframe.html"><B>All Classes</B></A>'); } //--></SCRIPT><NOSCRIPT> <A HREF="../../../../../allclasses-noframe.html"><B>All Classes</B></A></NOSCRIPT></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: <A HREF="#nested_class_summary">NESTED</A> | <A HREF="#field_summary">FIELD</A> | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: <A HREF="#field_detail">FIELD</A> | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><A NAME="skip-navbar_top"></A><!-- ========= END OF TOP NAVBAR ========= --><HR><!-- ======== START OF CLASS DATA ======== --><H2><FONT SIZE="-1">org.apache.commons.pool.impl</FONT><BR>Class GenericObjectPool</H2><PRE><A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html" title="class or interface in java.lang">java.lang.Object</A> <IMG SRC="../../../../../resources/inherit.gif" ALT="extended by "><A HREF="../../../../../org/apache/commons/pool/BaseObjectPool.html" title="class in org.apache.commons.pool">org.apache.commons.pool.BaseObjectPool</A> <IMG SRC="../../../../../resources/inherit.gif" ALT="extended by "><B>org.apache.commons.pool.impl.GenericObjectPool</B></PRE><DL><DT><B>All Implemented Interfaces:</B> <DD><A HREF="../../../../../org/apache/commons/pool/ObjectPool.html" title="interface in org.apache.commons.pool">ObjectPool</A></DD></DL><HR><DL><DT><PRE>public class <B>GenericObjectPool</B><DT>extends <A HREF="../../../../../org/apache/commons/pool/BaseObjectPool.html" title="class in org.apache.commons.pool">BaseObjectPool</A><DT>implements <A HREF="../../../../../org/apache/commons/pool/ObjectPool.html" title="interface in org.apache.commons.pool">ObjectPool</A></DL></PRE><P>A configurable <A HREF="../../../../../org/apache/commons/pool/ObjectPool.html" title="interface in org.apache.commons.pool"><CODE>ObjectPool</CODE></A> implementation. <p> When coupled with the appropriate <A HREF="../../../../../org/apache/commons/pool/PoolableObjectFactory.html" title="interface in org.apache.commons.pool"><CODE>PoolableObjectFactory</CODE></A>, <tt>GenericObjectPool</tt> provides robust pooling functionality for arbitrary objects. <p> A <tt>GenericObjectPool</tt> provides a number of configurable parameters: <ul> <li> <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#setMaxActive(int)"><CODE><i>maxActive</i></CODE></A> controls the maximum number of objects that can be borrowed from the pool at one time. When non-positive, there is no limit to the number of objects that may be active at one time. When <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#setMaxActive(int)"><CODE><i>maxActive</i></CODE></A> is exceeded, the pool is said to be exhausted. </li> <li> <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#setMaxIdle(int)"><CODE><i>maxIdle</i></CODE></A> controls the maximum number of objects that can sit idle in the pool at any time. When negative, there is no limit to the number of objects that may be idle at one time. </li> <li> <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#setWhenExhaustedAction(byte)"><CODE><i>whenExhaustedAction</i></CODE></A> specifies the behaviour of the <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#borrowObject()"><CODE>borrowObject()</CODE></A> method when the pool is exhausted: <ul> <li> When <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#setWhenExhaustedAction(byte)"><CODE><i>whenExhaustedAction</i></CODE></A> is <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#WHEN_EXHAUSTED_FAIL"><CODE>WHEN_EXHAUSTED_FAIL</CODE></A>, <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#borrowObject()"><CODE>borrowObject()</CODE></A> will throw a <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/util/NoSuchElementException.html" title="class or interface in java.util"><CODE>NoSuchElementException</CODE></A> </li> <li> When <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#setWhenExhaustedAction(byte)"><CODE><i>whenExhaustedAction</i></CODE></A> is <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#WHEN_EXHAUSTED_GROW"><CODE>WHEN_EXHAUSTED_GROW</CODE></A>, <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#borrowObject()"><CODE>borrowObject()</CODE></A> will create a new object and return it(essentially making <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#setMaxActive(int)"><CODE><i>maxActive</i></CODE></A> meaningless.) </li> <li> When <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#setWhenExhaustedAction(byte)"><CODE><i>whenExhaustedAction</i></CODE></A> is <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#WHEN_EXHAUSTED_BLOCK"><CODE>WHEN_EXHAUSTED_BLOCK</CODE></A>, <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#borrowObject()"><CODE>borrowObject()</CODE></A> will block (invoke <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html#wait(long)" title="class or interface in java.lang"><CODE>Object.wait(long)</CODE></A> until a new or idle object is available. If a positive <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#setMaxWait(long)"><CODE><i>maxWait</i></CODE></A> value is supplied, the <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#borrowObject()"><CODE>borrowObject()</CODE></A> will block for at most that many milliseconds, after which a <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/util/NoSuchElementException.html" title="class or interface in java.util"><CODE>NoSuchElementException</CODE></A> will be thrown. If <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#setMaxWait(long)"><CODE><i>maxWait</i></CODE></A> is non-positive, the <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#borrowObject()"><CODE>borrowObject()</CODE></A> method will block indefinitely. </li> </ul> </li> <li> When <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#setTestOnBorrow(boolean)"><CODE><i>testOnBorrow</i></CODE></A> is set, the pool will attempt to validate each object before it is returned from the <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#borrowObject()"><CODE>borrowObject()</CODE></A> method. (Using the provided factory's <A HREF="../../../../../org/apache/commons/pool/PoolableObjectFactory.html#validateObject(java.lang.Object)"><CODE>PoolableObjectFactory.validateObject(java.lang.Object)</CODE></A> method.) Objects that fail to validate will be dropped from the pool, and a different object will be borrowed. </li> <li> When <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#setTestOnReturn(boolean)"><CODE><i>testOnReturn</i></CODE></A> is set, the pool will attempt to validate each object before it is returned to the pool in the <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#returnObject(java.lang.Object)"><CODE>returnObject(java.lang.Object)</CODE></A> method. (Using the provided factory's <A HREF="../../../../../org/apache/commons/pool/PoolableObjectFactory.html#validateObject(java.lang.Object)"><CODE>PoolableObjectFactory.validateObject(java.lang.Object)</CODE></A> method.) Objects that fail to validate will be dropped from the pool. </li> </ul> <p> Optionally, one may configure the pool to examine and possibly evict objects as they sit idle in the pool. This is performed by an "idle object eviction" thread, which runs asychronously. The idle object eviction thread may be configured using the following attributes: <ul> <li> <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#setTimeBetweenEvictionRunsMillis(long)"><CODE><i>timeBetweenEvictionRunsMillis</i></CODE></A> indicates how long the eviction thread should sleep before "runs" of examining idle objects. When non-positive, no eviction thread will be launched. </li> <li> <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#setMinEvictableIdleTimeMillis(long)"><CODE><i>minEvictableIdleTimeMillis</i></CODE></A> specifies the minimum amount of time that an object may sit idle in the pool before it is eligable for eviction due to idle time. When non-positive, no object will be dropped from the pool due to idle time alone. </li> <li> <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#setTestWhileIdle(boolean)"><CODE><i>testWhileIdle</i></CODE></A> indicates whether or not idle objects should be validated using the factory's <A HREF="../../../../../org/apache/commons/pool/PoolableObjectFactory.html#validateObject(java.lang.Object)"><CODE>PoolableObjectFactory.validateObject(java.lang.Object)</CODE></A> method. Objects that fail to validate will be dropped from the pool. </li> </ul> <p> GenericObjectPool is not usable without a <A HREF="../../../../../org/apache/commons/pool/PoolableObjectFactory.html" title="interface in org.apache.commons.pool"><CODE>PoolableObjectFactory</CODE></A>. A non-<code>null</code> factory must be provided either as a constructor argument or via a call to <A HREF="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html#setFactory(org.apache.commons.pool.PoolableObjectFactory)"><CODE>setFactory(org.apache.commons.pool.PoolableObjectFactory)</CODE></A> before the pool is used.<P><P><DL><DT><B>Version:</B></DT> <DD>$Revision: 390563 $ $Date: 2006-03-31 20:28:14 -0500 (Fri, 31 Mar 2006) $</DD><DT><B>See Also:</B><DD><A HREF="../../../../../org/apache/commons/pool/impl/GenericKeyedObjectPool.html" title="class in org.apache.commons.pool.impl"><CODE>GenericKeyedObjectPool</CODE></A></DL><HR><P><!-- ======== NESTED CLASS SUMMARY ======== --><A NAME="nested_class_summary"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -