📄 genericobjectpool.html
字号:
<a name="385" href="#385">385</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="386" href="#386">386</a> <em> * @param testWhileIdle whether or not to validate objects in the idle object eviction thread, if any (see {@link #setTestWhileIdle})</em><a name="387" href="#387">387</a> <em> */</em><a name="388" href="#388">388</a> <strong>public</strong> <a href="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html">GenericObjectPool</a>(PoolableObjectFactory factory, <strong>int</strong> maxActive, byte whenExhaustedAction, <strong>long</strong> maxWait, <strong>int</strong> maxIdle, <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="389" href="#389">389</a> <strong>this</strong>(factory, maxActive, whenExhaustedAction, maxWait, maxIdle, minIdle, testOnBorrow, testOnReturn, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun, minEvictableIdleTimeMillis, testWhileIdle, DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);<a name="390" href="#390">390</a> }<a name="391" href="#391">391</a> <a name="392" href="#392">392</a> <em>/**<em>*</em></em><a name="393" href="#393">393</a> <em> * Create a new <tt>GenericObjectPool</tt> using the specified values.</em><a name="394" href="#394">394</a> <em> * @param factory the (possibly <tt>null</tt>)PoolableObjectFactory to use to create, validate and destroy objects</em><a name="395" href="#395">395</a> <em> * @param maxActive the maximum number of objects that can be borrowed from me at one time (see {@link #setMaxActive})</em><a name="396" href="#396">396</a> <em> * @param whenExhaustedAction the action to take when the pool is exhausted (see {@link #setWhenExhaustedAction})</em><a name="397" href="#397">397</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="398" href="#398">398</a> <em> * @param maxIdle the maximum number of idle objects in my pool (see {@link #setMaxIdle})</em><a name="399" href="#399">399</a> <em> * @param minIdle the minimum number of idle objects in my pool (see {@link #setMinIdle})</em><a name="400" href="#400">400</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="401" href="#401">401</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="402" href="#402">402</a> <em> * @param timeBetweenEvictionRunsMillis the amount of time (in milliseconds) to sleep between examining idle objects for eviction (see {@link #setTimeBetweenEvictionRunsMillis})</em><a name="403" href="#403">403</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="404" href="#404">404</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="405" href="#405">405</a> <em> * @param testWhileIdle whether or not to validate objects in the idle object eviction thread, if any (see {@link #setTestWhileIdle})</em><a name="406" href="#406">406</a> <em> * @param softMinEvictableIdleTimeMillis the minimum number of milliseconds an object can sit idle in the pool before it is eligable for evcition with the extra condition that at least "minIdle" amount of object remain in the pool. (see {@link #setSoftMinEvictableIdleTimeMillis})</em><a name="407" href="#407">407</a> <em> */</em><a name="408" href="#408">408</a> <strong>public</strong> <a href="../../../../../org/apache/commons/pool/impl/GenericObjectPool.html">GenericObjectPool</a>(PoolableObjectFactory factory, <strong>int</strong> maxActive, byte whenExhaustedAction, <strong>long</strong> maxWait, <strong>int</strong> maxIdle, <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, <strong>long</strong> softMinEvictableIdleTimeMillis) {<a name="409" href="#409">409</a> _factory = factory;<a name="410" href="#410">410</a> _maxActive = maxActive;<a name="411" href="#411">411</a> <strong>switch</strong>(whenExhaustedAction) {<a name="412" href="#412">412</a> <strong>case</strong> WHEN_EXHAUSTED_BLOCK:<a name="413" href="#413">413</a> <strong>case</strong> WHEN_EXHAUSTED_FAIL:<a name="414" href="#414">414</a> <strong>case</strong> WHEN_EXHAUSTED_GROW:<a name="415" href="#415">415</a> _whenExhaustedAction = whenExhaustedAction;<a name="416" href="#416">416</a> <strong>break</strong>;<a name="417" href="#417">417</a> <strong>default</strong>:<a name="418" href="#418">418</a> <strong>throw</strong> <strong>new</strong> IllegalArgumentException(<span class="string">"whenExhaustedAction "</span> + whenExhaustedAction + <span class="string">" not recognized."</span>);<a name="419" href="#419">419</a> }<a name="420" href="#420">420</a> _maxWait = maxWait;<a name="421" href="#421">421</a> _maxIdle = maxIdle;<a name="422" href="#422">422</a> _minIdle = minIdle;<a name="423" href="#423">423</a> _testOnBorrow = testOnBorrow;<a name="424" href="#424">424</a> _testOnReturn = testOnReturn;<a name="425" href="#425">425</a> _timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;<a name="426" href="#426">426</a> _numTestsPerEvictionRun = numTestsPerEvictionRun;<a name="427" href="#427">427</a> _minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;<a name="428" href="#428">428</a> _softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;<a name="429" href="#429">429</a> _testWhileIdle = testWhileIdle;<a name="430" href="#430">430</a> <a name="431" href="#431">431</a> _pool = <strong>new</strong> LinkedList();<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 total number of active instances from my pool.</em><a name="441" href="#441">441</a> <em> * @return the cap on the total number of active instances from my pool.</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 total number of active instances from my pool.</em><a name="450" href="#450">450</a> <em> * @param maxActive The cap on the total number of active instances from my pool.</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 action to take when the {@link #borrowObject} method</em><a name="461" href="#461">461</a> <em> * is invoked when the pool is exhausted (the maximum number</em><a name="462" href="#462">462</a> <em> * of "active" objects has been reached).</em><a name="463" href="#463">463</a> <em> *</em><a name="464" href="#464">464</a> <em> * @return one of {@link #WHEN_EXHAUSTED_BLOCK}, {@link #WHEN_EXHAUSTED_FAIL} or {@link #WHEN_EXHAUSTED_GROW}</em><a name="465" href="#465">465</a> <em> * @see #setWhenExhaustedAction</em><a name="466" href="#466">466</a> <em> */</em><a name="467" href="#467">467</a> <strong>public</strong> <strong>synchronized</strong> byte getWhenExhaustedAction() {<a name="468" href="#468">468</a> <strong>return</strong> _whenExhaustedAction;<a name="469" href="#469">469</a> }<a name="470" href="#470">470</a> <a name="471" href="#471">471</a> <em>/**<em>*</em></em><a name="472" href="#472">472</a> <em> * Sets the action to take when the {@link #borrowObject} method</em><a name="473" href="#473">473</a> <em> * is invoked when the pool is exhausted (the maximum number</em><a name="474" href="#474">474</a> <em> * of "active" objects has been reached).</em><a name="475" href="#475">475</a> <em> *</em><a name="476" href="#476">476</a> <em> * @param whenExhaustedAction the action code, which must be one of</em><a name="477" href="#477">477</a> <em> * {@link #WHEN_EXHAUSTED_BLOCK}, {@link #WHEN_EXHAUSTED_FAIL},</em><a name="478" href="#478">478</a> <em> * or {@link #WHEN_EXHAUSTED_GROW}</em><a name="479" href="#479">479</a> <em> * @see #getWhenExhaustedAction</em><a name="480" href="#480">480</a> <em> */</em><a name="481" href="#481">481</a> <strong>public</strong> <strong>synchronized</strong> <strong>void</strong> setWhenExhaustedAction(byte whenExhaustedAction) {<a name="482" href="#482">482</a> <strong>switch</strong>(whenExhaustedAction) {<a name="483" href="#483">483</a> <strong>case</strong> WHEN_EXHAUSTED_BLOCK:<a name="484" href="#484">484</a> <strong>case</strong> WHEN_EXHAUSTED_FAIL:<a name="485" href="#485">485</a> <strong>case</strong> WHEN_EXHAUSTED_GROW:<a name="486" href="#486">486</a> _whenExhaustedAction = whenExhaustedAction;<a name="487" href="#487">487</a> notifyAll();<a name="488" href="#488">488</a> <strong>break</strong>;<a name="489" href="#489">489</a> <strong>default</strong>:<a name="490" href="#490">490</a> <strong>throw</strong> <strong>new</strong> IllegalArgumentException(<span class="string">"whenExhaustedAction "</span> + whenExhaustedAction + <span class="string">" not recognized."</span>);<a name="491" href="#491">491</a> }<a name="492" href="#492">492</a> }<a name="493" href="#493">493</a> <a name="494" href="#494">494</a> <a name="495" href="#495">495</a> <em>/**<em>*</em></em><a name="496" href="#496">496</a> <em> * Returns the maximum amount of time (in milliseconds) the</em><a name="497" href="#497">497</a> <em> * {@link #borrowObject} method should block before throwing</em><a name="498" href="#498">498</a> <em> * an exception when the pool is exhausted and the</em><a name="499" href="#499">499</a> <em> * {@link #setWhenExhaustedAction "when exhausted" action} is</em><a name="500" href="#500">500</a> <em> * {@link #WHEN_EXHAUSTED_BLOCK}.</em><a name="501" href="#501">501</a> <em> *</em><a name="502" href="#502">502</a> <em> * When less than 0, the {@link #borrowObject} method</em><a name="503" href="#503">503</a> <em> * may block indefinitely.</em><a name="504" href="#504">504</a> <em> *</em><a name="505" href="#505">505</a> <em> * @see #setMaxWait</em><a name="506" href="#506">506</a> <em> * @see #setWhenExhaustedAction</em><a name="507" href="#507">507</a> <em> * @see #WHEN_EXHAUSTED_BLOCK</em><a name="508" href="#508">508</a> <em> */</em><a name="509" href="#509">509</a> <strong>public</strong> <strong>synchronized</strong> <strong>long</strong> getMaxWait() {<a name="510" href="#510">510</a> <strong>return</strong> _maxWait;<a name="511" href="#511">511</a> }<a name="512" href="#512">512</a> <a name="513" href="#513">513</a> <em>/**<em>*</em></em><a name="514" href="#514">514</a> <em> * Sets the maximum amount of time (in milliseconds) the</em><a name="515" href="#515">515</a> <em> * {@link #borrowObject} method should block before throwing</em>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -