Added takeUniterruptibly (ignores InterruptedException and returns null)
This commit is contained in:
parent
8f8aa8e828
commit
0d3413d501
|
@ -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);
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue