📄 generickeyedobjectpool.html
字号:
<a name="376" href="#376">376</a> <em> * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted an and <i>whenExhaustedAction</i> is {@link #WHEN_EXHAUSTED_BLOCK} (otherwise ignored) (see {@link #setMaxWait})</em><a name="377" href="#377">377</a> <em> * @param maxIdle the maximum number of idle objects in my pool (see {@link #setMaxIdle})</em><a name="378" href="#378">378</a> <em> * @param maxTotal the maximum number of objects that can exists at one time (see {@link #setMaxTotal})</em><a name="379" href="#379">379</a> <em> * @param testOnBorrow whether or not to validate objects before they are returned by the {@link #borrowObject} method (see {@link #setTestOnBorrow})</em><a name="380" href="#380">380</a> <em> * @param testOnReturn whether or not to validate objects after they are returned to the {@link #returnObject} method (see {@link #setTestOnReturn})</em><a name="381" href="#381">381</a> <em> * @param timeBetweenEvictionRunsMillis the amount of time (in milliseconds) to sleep between examining idle objects for eviction (see {@link #setTimeBetweenEvictionRunsMillis})</em><a name="382" href="#382">382</a> <em> * @param numTestsPerEvictionRun the number of idle objects to examine per run within the idle object eviction thread (if any) (see {@link #setNumTestsPerEvictionRun})</em><a name="383" href="#383">383</a> <em> * @param minEvictableIdleTimeMillis the minimum number of milliseconds an object can sit idle in the pool before it is eligable for evcition (see {@link #setMinEvictableIdleTimeMillis})</em><a name="384" href="#384">384</a> <em> * @param testWhileIdle whether or not to validate objects in the idle object eviction thread, if any (see {@link #setTestWhileIdle})</em><a name="385" href="#385">385</a> <em> */</em><a name="386" href="#386">386</a> <strong>public</strong> <a href="../../../../../org/apache/commons/pool/impl/GenericKeyedObjectPool.html">GenericKeyedObjectPool</a>(<a href="../../../../../org/apache/commons/pool/KeyedPoolableObjectFactory.html">KeyedPoolableObjectFactory</a> factory, <strong>int</strong> maxActive, byte whenExhaustedAction, <strong>long</strong> maxWait, <strong>int</strong> maxIdle, <strong>int</strong> maxTotal, <strong>boolean</strong> testOnBorrow, <strong>boolean</strong> testOnReturn, <strong>long</strong> timeBetweenEvictionRunsMillis, <strong>int</strong> numTestsPerEvictionRun, <strong>long</strong> minEvictableIdleTimeMillis, <strong>boolean</strong> testWhileIdle) {<a name="387" href="#387">387</a> <strong>this</strong>(factory, maxActive, whenExhaustedAction, maxWait, maxIdle, maxTotal, GenericKeyedObjectPool.DEFAULT_MIN_IDLE, testOnBorrow, testOnReturn, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun, minEvictableIdleTimeMillis, testWhileIdle);<a name="388" href="#388">388</a> }<a name="389" href="#389">389</a> <a name="390" href="#390">390</a> <em>/**<em>*</em></em><a name="391" href="#391">391</a> <em> * Create a new <tt>GenericKeyedObjectPool</tt> using the specified values.</em><a name="392" href="#392">392</a> <em> * @param factory the (possibly <tt>null</tt>)PoolableObjectFactory to use to create, validate and destroy objects</em><a name="393" href="#393">393</a> <em> * @param maxActive the maximum number of objects that can be borrowed from me at one time (per key) (see {@link #setMaxActive})</em><a name="394" href="#394">394</a> <em> * @param whenExhaustedAction the action to take when the pool is exhausted (see {@link #setWhenExhaustedAction})</em><a name="395" href="#395">395</a> <em> * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted an and <i>whenExhaustedAction</i> is {@link #WHEN_EXHAUSTED_BLOCK} (otherwise ignored) (see {@link #setMaxWait})</em><a name="396" href="#396">396</a> <em> * @param maxIdle the maximum number of idle objects in my pool (see {@link #setMaxIdle})</em><a name="397" href="#397">397</a> <em> * @param maxTotal the maximum number of objects that can exists at one time (see {@link #setMaxTotal})</em><a name="398" href="#398">398</a> <em> * @param minIdle the minimum number of idle objects to have in the pool at any one time (see {@link #setMinIdle})</em><a name="399" href="#399">399</a> <em> * @param testOnBorrow whether or not to validate objects before they are returned by the {@link #borrowObject} method (see {@link #setTestOnBorrow})</em><a name="400" href="#400">400</a> <em> * @param testOnReturn whether or not to validate objects after they are returned to the {@link #returnObject} method (see {@link #setTestOnReturn})</em><a name="401" href="#401">401</a> <em> * @param timeBetweenEvictionRunsMillis the amount of time (in milliseconds) to sleep between examining idle objects for eviction (see {@link #setTimeBetweenEvictionRunsMillis})</em><a name="402" href="#402">402</a> <em> * @param numTestsPerEvictionRun the number of idle objects to examine per run within the idle object eviction thread (if any) (see {@link #setNumTestsPerEvictionRun})</em><a name="403" href="#403">403</a> <em> * @param minEvictableIdleTimeMillis the minimum number of milliseconds an object can sit idle in the pool before it is eligable for evcition (see {@link #setMinEvictableIdleTimeMillis})</em><a name="404" href="#404">404</a> <em> * @param testWhileIdle whether or not to validate objects in the idle object eviction thread, if any (see {@link #setTestWhileIdle})</em><a name="405" href="#405">405</a> <em> */</em><a name="406" href="#406">406</a> <strong>public</strong> <a href="../../../../../org/apache/commons/pool/impl/GenericKeyedObjectPool.html">GenericKeyedObjectPool</a>(<a href="../../../../../org/apache/commons/pool/KeyedPoolableObjectFactory.html">KeyedPoolableObjectFactory</a> factory, <strong>int</strong> maxActive, byte whenExhaustedAction, <strong>long</strong> maxWait, <strong>int</strong> maxIdle, <strong>int</strong> maxTotal, <strong>int</strong> minIdle, <strong>boolean</strong> testOnBorrow, <strong>boolean</strong> testOnReturn, <strong>long</strong> timeBetweenEvictionRunsMillis, <strong>int</strong> numTestsPerEvictionRun, <strong>long</strong> minEvictableIdleTimeMillis, <strong>boolean</strong> testWhileIdle) {<a name="407" href="#407">407</a> _factory = factory;<a name="408" href="#408">408</a> _maxActive = maxActive;<a name="409" href="#409">409</a> <strong>switch</strong>(whenExhaustedAction) {<a name="410" href="#410">410</a> <strong>case</strong> WHEN_EXHAUSTED_BLOCK:<a name="411" href="#411">411</a> <strong>case</strong> WHEN_EXHAUSTED_FAIL:<a name="412" href="#412">412</a> <strong>case</strong> WHEN_EXHAUSTED_GROW:<a name="413" href="#413">413</a> _whenExhaustedAction = whenExhaustedAction;<a name="414" href="#414">414</a> <strong>break</strong>;<a name="415" href="#415">415</a> <strong>default</strong>:<a name="416" href="#416">416</a> <strong>throw</strong> <strong>new</strong> IllegalArgumentException(<span class="string">"whenExhaustedAction "</span> + whenExhaustedAction + <span class="string">" not recognized."</span>);<a name="417" href="#417">417</a> }<a name="418" href="#418">418</a> _maxWait = maxWait;<a name="419" href="#419">419</a> _maxIdle = maxIdle;<a name="420" href="#420">420</a> _maxTotal = maxTotal;<a name="421" href="#421">421</a> _minIdle = minIdle;<a name="422" href="#422">422</a> _testOnBorrow = testOnBorrow;<a name="423" href="#423">423</a> _testOnReturn = testOnReturn;<a name="424" href="#424">424</a> _timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;<a name="425" href="#425">425</a> _numTestsPerEvictionRun = numTestsPerEvictionRun;<a name="426" href="#426">426</a> _minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;<a name="427" href="#427">427</a> _testWhileIdle = testWhileIdle;<a name="428" href="#428">428</a> <a name="429" href="#429">429</a> _poolMap = <strong>new</strong> HashMap();<a name="430" href="#430">430</a> _activeMap = <strong>new</strong> HashMap();<a name="431" href="#431">431</a> <a name="432" href="#432">432</a> startEvictor(_timeBetweenEvictionRunsMillis);<a name="433" href="#433">433</a> }<a name="434" href="#434">434</a> <a name="435" href="#435">435</a> <em class="comment">//--- public methods ---------------------------------------------</em><a name="436" href="#436">436</a> <a name="437" href="#437">437</a> <em class="comment">//--- configuration methods --------------------------------------</em><a name="438" href="#438">438</a> <a name="439" href="#439">439</a> <em>/**<em>*</em></em><a name="440" href="#440">440</a> <em> * Returns the cap on the number of active instances from my pool (per key).</em><a name="441" href="#441">441</a> <em> * @return the cap on the number of active instances from my pool (per key).</em><a name="442" href="#442">442</a> <em> * @see #setMaxActive</em><a name="443" href="#443">443</a> <em> */</em><a name="444" href="#444">444</a> <strong>public</strong> <strong>synchronized</strong> <strong>int</strong> getMaxActive() {<a name="445" href="#445">445</a> <strong>return</strong> _maxActive;<a name="446" href="#446">446</a> }<a name="447" href="#447">447</a> <a name="448" href="#448">448</a> <em>/**<em>*</em></em><a name="449" href="#449">449</a> <em> * Sets the cap on the number of active instances from my pool (per key).</em><a name="450" href="#450">450</a> <em> * @param maxActive The cap on the number of active instances from my pool (per key).</em><a name="451" href="#451">451</a> <em> * Use a negative value for an infinite number of instances.</em><a name="452" href="#452">452</a> <em> * @see #getMaxActive</em><a name="453" href="#453">453</a> <em> */</em><a name="454" href="#454">454</a> <strong>public</strong> <strong>synchronized</strong> <strong>void</strong> setMaxActive(<strong>int</strong> maxActive) {<a name="455" href="#455">455</a> _maxActive = maxActive;<a name="456" href="#456">456</a> notifyAll();<a name="457" href="#457">457</a> }<a name="458" href="#458">458</a> <a name="459" href="#459">459</a> <em>/**<em>*</em></em><a name="460" href="#460">460</a> <em> * Returns the cap on the total number of instances from my pool if non-positive.</em><a name="461" href="#461">461</a> <em> * @return the cap on the total number of instances from my pool if non-positive.</em><a name="462" href="#462">462</a> <em> * @see #setMaxTotal</em><a name="463" href="#463">463</a> <em> */</em><a name="464" href="#464">464</a> <strong>public</strong> <strong>synchronized</strong> <strong>int</strong> getMaxTotal() {<a name="465" href="#465">465</a> <strong>return</strong> _maxTotal;<a name="466" href="#466">466</a> }<a name="467" href="#467">467</a> <a name="468" href="#468">468</a> <em>/**<em>*</em></em><a name="469" href="#469">469</a> <em> * Sets the cap on the total number of instances from my pool if non-positive.</em><a name="470" href="#470">470</a> <em> * @param maxTotal The cap on the total number of instances from my pool.</em><a name="471" href="#471">471</a> <em> * Use a non-positive value for an infinite number of instances.</em><a name="472" href="#472">472</a> <em> * @see #getMaxTotal</em><a name="473" href="#473">473</a> <em> */</em><a name="474" href="#474">474</a> <strong>public</strong> <strong>synchronized</strong> <strong>void</strong> setMaxTotal(<strong>int</strong> maxTotal) {<a name="475" href="#475">475</a> _maxTotal = maxTotal;<a name="476" href="#476">476</a> notifyAll();<a name="477" href="#477">477</a> }<a name="478" href="#478">478</a> <a name="479" href="#479">479</a> <em>/**<em>*</em></em><a name="480" href="#480">480</a> <em> * Returns the action to take when the {@link #borrowObject} method</em><a name="481" href="#481">481</a> <em> * is invoked when the pool is exhausted (the maximum number</em><a name="482" href="#482">482</a> <em> * of "active" objects has been reached).</em><a name="483" href="#483">483</a> <em> *</em><a name="484" href="#484">484</a> <em> * @return one of {@link #WHEN_EXHAUSTED_BLOCK}, {@link #WHEN_EXHAUSTED_FAIL} or {@link #WHEN_EXHAUSTED_GROW}</em><a name="485" href="#485">485</a> <em> * @see #setWhenExhaustedAction</em><a name="486" href="#486">486</a> <em> */</em><a name="487" href="#487">487</a> <strong>public</strong> <strong>synchronized</strong> byte getWhenExhaustedAction() {<a name="488" href="#488">488</a> <strong>return</strong> _whenExhaustedAction;<a name="489" href="#489">489</a> }<a name="490" href="#490">490</a> <a name="491" href="#491">491</a> <em>/**<em>*</em></em><a name="492" href="#492">492</a> <em> * Sets the action to take when the {@link #borrowObject} method</em><a name="493" href="#493">493</a> <em> * is invoked when the pool is exhausted (the maximum number</em><a name="494" href="#494">494</a> <em> * of "active" objects has been reached).</em><a name="495" href="#495">495</a> <em> *</em><a name="496" href="#496">496</a> <em> * @param whenExhaustedAction the action code, which must be one of</em><a name="497" href="#497">497</a> <em> * {@link #WHEN_EXHAUSTED_BLOCK}, {@link #WHEN_EXHAUSTED_FAIL},</em><a name="498" href="#498">498</a> <em> * or {@link #WHEN_EXHAUSTED_GROW}</em><a name="499" href="#499">499</a> <em> * @see #getWhenExhaustedAction</em><a name="500" href="#500">500</a> <em> */</em><a name="501" href="#501">501</a> <strong>public</strong> <strong>synchronized</strong> <strong>void</strong> setWhenExhaustedAction(byte whenExhaustedAction) {<a name="502" href="#502">502</a> <strong>switch</strong>(whenExhaustedAction) {<a name="503" href="#503">503</a> <strong>case</strong> WHEN_EXHAUSTED_BLOCK:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -