⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 poolutils.html

📁 优秀的文档,可以学习java之用 0006728337 00000 n 0006728424 00000 n 0006728600 00000 n
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<a name="258" href="#258">258</a>     <em>/**<em>*</em></em><a name="259" href="#259">259</a> <em>     * Call &lt;code>addObject()&lt;/code> on &lt;code>keyedPool&lt;/code> &lt;code>count&lt;/code> number of times.</em><a name="260" href="#260">260</a> <em>     *</em><a name="261" href="#261">261</a> <em>     * @param pool the keyedPool to prefill.</em><a name="262" href="#262">262</a> <em>     * @param count the number of idle objects to add.</em><a name="263" href="#263">263</a> <em>     * @throws Exception when {@link ObjectPool#addObject()} fails.</em><a name="264" href="#264">264</a> <em>     * @throws IllegalArgumentException when &lt;code>keyedPool&lt;/code> is &lt;code>null&lt;/code>.</em><a name="265" href="#265">265</a> <em>     * @since Pool 1.3</em><a name="266" href="#266">266</a> <em>     */</em><a name="267" href="#267">267</a>     <strong>public</strong> <strong>static</strong> <strong>void</strong> prefill(<strong>final</strong> <a href="../../../../org/apache/commons/pool/ObjectPool.html">ObjectPool</a> pool, <strong>final</strong> <strong>int</strong> count) throws Exception, IllegalArgumentException {<a name="268" href="#268">268</a>         <strong>if</strong> (pool == <strong>null</strong>) {<a name="269" href="#269">269</a>             <strong>throw</strong> <strong>new</strong> IllegalArgumentException(<span class="string">"keyedPool must not be null."</span>);<a name="270" href="#270">270</a>         }<a name="271" href="#271">271</a>         <strong>for</strong> (<strong>int</strong> i = 0; i &lt; count; i++) {<a name="272" href="#272">272</a>             pool.addObject();<a name="273" href="#273">273</a>         }<a name="274" href="#274">274</a>     }<a name="275" href="#275">275</a> <a name="276" href="#276">276</a>     <em>/**<em>*</em></em><a name="277" href="#277">277</a> <em>     * Call &lt;code>addObject(Object)&lt;/code> on &lt;code>keyedPool&lt;/code> with &lt;code>key&lt;/code> &lt;code>count&lt;/code></em><a name="278" href="#278">278</a> <em>     * number of times.</em><a name="279" href="#279">279</a> <em>     *</em><a name="280" href="#280">280</a> <em>     * @param keyedPool the keyedPool to prefill.</em><a name="281" href="#281">281</a> <em>     * @param key the key to add objects for.</em><a name="282" href="#282">282</a> <em>     * @param count the number of idle objects to add for &lt;code>key&lt;/code>.</em><a name="283" href="#283">283</a> <em>     * @throws Exception when {@link KeyedObjectPool#addObject(Object)} fails.</em><a name="284" href="#284">284</a> <em>     * @throws IllegalArgumentException when &lt;code>keyedPool&lt;/code> or &lt;code>key&lt;/code> is &lt;code>null&lt;/code>.</em><a name="285" href="#285">285</a> <em>     * @since Pool 1.3</em><a name="286" href="#286">286</a> <em>     */</em><a name="287" href="#287">287</a>     <strong>public</strong> <strong>static</strong> <strong>void</strong> prefill(<strong>final</strong> <a href="../../../../org/apache/commons/pool/KeyedObjectPool.html">KeyedObjectPool</a> keyedPool, <strong>final</strong> Object key, <strong>final</strong> <strong>int</strong> count) throws Exception, IllegalArgumentException {<a name="288" href="#288">288</a>         <strong>if</strong> (keyedPool == <strong>null</strong>) {<a name="289" href="#289">289</a>             <strong>throw</strong> <strong>new</strong> IllegalArgumentException(<span class="string">"keyedPool must not be null."</span>);<a name="290" href="#290">290</a>         }<a name="291" href="#291">291</a>         <strong>if</strong> (key == <strong>null</strong>) {<a name="292" href="#292">292</a>             <strong>throw</strong> <strong>new</strong> IllegalArgumentException(<span class="string">"key must not be null."</span>);<a name="293" href="#293">293</a>         }<a name="294" href="#294">294</a>         <strong>for</strong> (<strong>int</strong> i = 0; i &lt; count; i++) {<a name="295" href="#295">295</a>             keyedPool.addObject(key);<a name="296" href="#296">296</a>         }<a name="297" href="#297">297</a>     }<a name="298" href="#298">298</a> <a name="299" href="#299">299</a>     <em>/**<em>*</em></em><a name="300" href="#300">300</a> <em>     * Call &lt;code>addObject(Object)&lt;/code> on &lt;code>keyedPool&lt;/code> with each key in &lt;code>keys&lt;/code> for</em><a name="301" href="#301">301</a> <em>     * &lt;code>count&lt;/code> number of times. This has the same effect as calling</em><a name="302" href="#302">302</a> <em>     * {@link #prefill(KeyedObjectPool, Object, int)} for each key in the &lt;code>keys&lt;/code> collection.</em><a name="303" href="#303">303</a> <em>     *</em><a name="304" href="#304">304</a> <em>     * @param keyedPool the keyedPool to prefill.</em><a name="305" href="#305">305</a> <em>     * @param keys {@link Collection} of keys to add objects for.</em><a name="306" href="#306">306</a> <em>     * @param count the number of idle objects to add for each &lt;code>key&lt;/code>.</em><a name="307" href="#307">307</a> <em>     * @throws Exception when {@link KeyedObjectPool#addObject(Object)} fails.</em><a name="308" href="#308">308</a> <em>     * @throws IllegalArgumentException when &lt;code>keyedPool&lt;/code>, &lt;code>keys&lt;/code>, or</em><a name="309" href="#309">309</a> <em>     *      any value in &lt;code>keys&lt;/code> is &lt;code>null&lt;/code>.</em><a name="310" href="#310">310</a> <em>     * @see #prefill(KeyedObjectPool, Object, int)</em><a name="311" href="#311">311</a> <em>     * @since Pool 1.3</em><a name="312" href="#312">312</a> <em>     */</em><a name="313" href="#313">313</a>     <strong>public</strong> <strong>static</strong> <strong>void</strong> prefill(<strong>final</strong> <a href="../../../../org/apache/commons/pool/KeyedObjectPool.html">KeyedObjectPool</a> keyedPool, <strong>final</strong> Collection keys, <strong>final</strong> <strong>int</strong> count) throws Exception, IllegalArgumentException {<a name="314" href="#314">314</a>         <strong>if</strong> (keys == <strong>null</strong>) {<a name="315" href="#315">315</a>             <strong>throw</strong> <strong>new</strong> IllegalArgumentException(<span class="string">"keys must not be null."</span>);<a name="316" href="#316">316</a>         }<a name="317" href="#317">317</a>         <strong>final</strong> Iterator iter = keys.iterator();<a name="318" href="#318">318</a>         <strong>while</strong> (iter.hasNext()) {<a name="319" href="#319">319</a>             prefill(keyedPool, iter.next(), count);<a name="320" href="#320">320</a>         }<a name="321" href="#321">321</a>     }<a name="322" href="#322">322</a> <a name="323" href="#323">323</a>     <em>/**<em>*</em></em><a name="324" href="#324">324</a> <em>     * Returns a synchronized (thread-safe) ObjectPool backed by the specified ObjectPool.</em><a name="325" href="#325">325</a> <em>     *</em><a name="326" href="#326">326</a> <em>     * @param pool the ObjectPool to be "wrapped" in a synchronized ObjectPool.</em><a name="327" href="#327">327</a> <em>     * @return a synchronized view of the specified ObjectPool.</em><a name="328" href="#328">328</a> <em>     * @since Pool 1.3</em><a name="329" href="#329">329</a> <em>     */</em><a name="330" href="#330">330</a>     <strong>public</strong> <strong>static</strong> <a href="../../../../org/apache/commons/pool/ObjectPool.html">ObjectPool</a> synchronizedPool(<strong>final</strong> <a href="../../../../org/apache/commons/pool/ObjectPool.html">ObjectPool</a> pool) {<a name="331" href="#331">331</a>         <strong>return</strong> <strong>new</strong> SynchronizedObjectPool(pool);<a name="332" href="#332">332</a>     }<a name="333" href="#333">333</a> <a name="334" href="#334">334</a>     <em>/**<em>*</em></em><a name="335" href="#335">335</a> <em>     * Returns a synchronized (thread-safe) KeyedObjectPool backed by the specified KeyedObjectPool.</em><a name="336" href="#336">336</a> <em>     * </em><a name="337" href="#337">337</a> <em>     * @param keyedPool the KeyedObjectPool to be "wrapped" in a synchronized KeyedObjectPool.</em><a name="338" href="#338">338</a> <em>     * @return a synchronized view of the specified KeyedObjectPool.</em><a name="339" href="#339">339</a> <em>     * @since Pool 1.3</em><a name="340" href="#340">340</a> <em>     */</em><a name="341" href="#341">341</a>     <strong>public</strong> <strong>static</strong> <a href="../../../../org/apache/commons/pool/KeyedObjectPool.html">KeyedObjectPool</a> synchronizedPool(<strong>final</strong> <a href="../../../../org/apache/commons/pool/KeyedObjectPool.html">KeyedObjectPool</a> keyedPool) {<a name="342" href="#342">342</a>         <strong>return</strong> <strong>new</strong> SynchronizedKeyedObjectPool(keyedPool);<a name="343" href="#343">343</a>     }<a name="344" href="#344">344</a> <a name="345" href="#345">345</a>     <em>/**<em>*</em></em><a name="346" href="#346">346</a> <em>     * Returns a synchronized (thread-safe) PoolableObjectFactory backed by the specified PoolableObjectFactory.</em><a name="347" href="#347">347</a> <em>     *</em><a name="348" href="#348">348</a> <em>     * @param factory the PoolableObjectFactory to be "wrapped" in a synchronized PoolableObjectFactory.</em><a name="349" href="#349">349</a> <em>     * @return a synchronized view of the specified PoolableObjectFactory.</em><a name="350" href="#350">350</a> <em>     * @since Pool 1.3</em><a name="351" href="#351">351</a> <em>     */</em><a name="352" href="#352">352</a>     <strong>public</strong> <strong>static</strong> <a href="../../../../org/apache/commons/pool/PoolableObjectFactory.html">PoolableObjectFactory</a> synchronizedPoolableFactory(<strong>final</strong> <a href="../../../../org/apache/commons/pool/PoolableObjectFactory.html">PoolableObjectFactory</a> factory) {<a name="353" href="#353">353</a>         <strong>return</strong> <strong>new</strong> SynchronizedPoolableObjectFactory(factory);<a name="354" href="#354">354</a>     }<a name="355" href="#355">355</a> <a name="356" href="#356">356</a>     <em>/**<em>*</em></em><a name="357" href="#357">357</a> <em>     * Returns a synchronized (thread-safe) KeyedPoolableObjectFactory backed by the specified KeyedPoolableObjectFactory.</em><a name="358" href="#358">358</a> <em>     *</em><a name="359" href="#359">359</a> <em>     * @param keyedFactory the KeyedPoolableObjectFactory to be "wrapped" in a synchronized KeyedPoolableObjectFactory.</em><a name="360" href="#360">360</a> <em>     * @return a synchronized view of the specified KeyedPoolableObjectFactory.</em><a name="361" href="#361">361</a> <em>     * @since Pool 1.3</em><a name="362" href="#362">362</a> <em>     */</em><a name="363" href="#363">363</a>     <strong>public</strong> <strong>static</strong> <a href="../../../../org/apache/commons/pool/KeyedPoolableObjectFactory.html">KeyedPoolableObjectFactory</a> synchronizedPoolableFactory(<strong>final</strong> <a href="../../../../org/apache/commons/pool/KeyedPoolableObjectFactory.html">KeyedPoolableObjectFactory</a> keyedFactory) {<a name="364" href="#364">364</a>         <strong>return</strong> <strong>new</strong> SynchronizedKeyedPoolableObjectFactory(keyedFactory);<a name="365" href="#365">365</a>     }<a name="366" href="#366">366</a> <a name="367" href="#367">367</a>     <em>/**<em>*</em></em><a name="368" href="#368">368</a> <em>     * Get the &lt;code>Timer&lt;/code> for checking keyedPool's idle count. Lazily create the {@link Timer} as needed.</em><a name="369" href="#369">369</a> <em>     *</em><a name="370" href="#370">370</a> <em>     * @return the {@link Timer} for checking keyedPool's idle count.</em><a name="371" href="#371">371</a> <em>     * @since Pool 1.3</em><a name="372" href="#372">372</a> <em>     */</em><a name="373" href="#373">373</a>     <strong>private</strong> <strong>static</strong> <strong>synchronized</strong> Timer getMinIdleTimer() {<a name="374" href="#374">374</a>         <strong>if</strong> (MIN_IDLE_TIMER == <strong>null</strong>) {<a name="375" href="#375">375</a>             MIN_IDLE_TIMER = <strong>new</strong> Timer(<strong>true</strong>);<a name="376" href="#376">376</a>         }<a name="377" href="#377">377</a>         <strong>return</strong> MIN_IDLE_TIMER;<a name="378" href="#378">378</a>     }<a name="379" href="#379">379</a> <a name="380" href="#380">380</a>     <strong>private</strong> <strong>static</strong> <strong>class</strong> PoolableObjectFactoryAdaptor implements <a href="../../../../org/apache/commons/pool/PoolableObjectFactory.html">PoolableObjectFactory</a> {<a name="381" href="#381">381</a>         <strong>private</strong> <strong>final</strong> Object key;<a name="382" href="#382">382</a>         <strong>private</strong> <strong>final</strong> <a href="../../../../org/apache/commons/pool/KeyedPoolableObjectFactory.html">KeyedPoolableObjectFactory</a> keyedFactory;<a name="383" href="#383">383</a> <a name="384" href="#384">384</a>         PoolableObjectFactoryAdaptor(<strong>final</strong> <a href="../../../../org/apache/commons/pool/KeyedPoolableObjectFactory.html">KeyedPoolableObjectFactory</a> keyedFactory, <strong>final</strong> Object key) throws IllegalArgumentException {<a name="385" href="#385">385</a>             <strong>if</strong> (keyedFactory == <strong>null</strong>) {<a name="386" href="#386">386</a>                 <strong>throw</strong> <strong>new</strong> IllegalArgumentException(<span class="string">"keyedFactory must not be null."</span>);<a name="387" href="#387">387</a>             }<a name="388" href="#388">388</a>             <strong>if</strong> (key == <strong>null</strong>) {<a name="389" href="#389">389</a>                 <strong>throw</strong> <strong>new</strong> IllegalArgumentException(<span class="string">"key must not be null."</span>);<a name="390" href="#390">390</a>             }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -