Added takeUniterruptibly (ignores InterruptedException and returns null)

This commit is contained in:
nathan 2015-07-20 16:47:34 +02:00
parent 8f8aa8e828
commit 0d3413d501
3 changed files with 31 additions and 2 deletions

View File

@ -15,15 +15,24 @@
*/
package dorkbox.util.objectPool;
@SuppressWarnings("ALL")
public
interface ObjectPool<T> {
/**
* Takes an object from the pool
* Takes an object from the pool, Blocks until an item is available in the pool.
*/
T take() throws InterruptedException;
/**
* Return object to the pool
* Takes an object from the pool, Blocks until an item is available in the pool.
* <p/>
* This method catches an
* {@link InterruptedException} and discards it silently.
*/
T takeUninterruptibly();
/**
* Return object to the pool, waking those that have blocked during take()
*/
void release(T object);

View File

@ -42,6 +42,16 @@ class SafeObjectPool<T> implements ObjectPool<T> {
return this.queue.take();
}
@Override
public
T takeUninterruptibly() {
try {
return take();
} catch (InterruptedException e) {
return null;
}
}
@Override
public
void release(T object) {

View File

@ -62,6 +62,16 @@ class UnsafeObjectPool<T> implements ObjectPool<T> {
return poll;
}
@Override
public
T takeUninterruptibly() {
try {
return take();
} catch (InterruptedException e) {
return null;
}
}
@Override
public
void release(T object) {