Java 并發對象池:Vibur Object Pool

jopen 10年前發布 | 19K 次閱讀 Java開發 Vibur Object Pool

Vibur Object Pool 是個通用并發 Java 對象池,提供驗證和非驗證池。 它是完全是用標準Java concurrency utilities創建,不需要用到任何同步塊或者方法,也不需要任何外部依賴。這對于高消耗的 Java 對象創建,類似數據庫連接或者其他 socket 連接遠程主機的池或者緩存池是個非常棒的選擇。

HolderValidatingPoolService<SomeClass> pool = new ConcurrentHolderLinkedPool<SomeClass>(
        new SomeClassFactory(), 10, 60, false);

//...

Holder<SomeClass> hObj = null; try { hObj = pool.tryTake(10, TimeUnit.SECONDS); if (hObj == null) // i.e. no any object was available in the pool for 10 seconds return;

// do some work and use hObj.value() here

} finally { if (hObj != null) pool.restore(hObj, true); }</pre>

項目主頁:http://www.baiduhome.net/lib/view/home/1391952079114

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!