mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-25 21:42:07 +01:00
Add ArrayBlockingQueueWithShutdown.tryPut(E)
This commit is contained in:
parent
59ac41faef
commit
c7697ea9d0
1 changed files with 20 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2014 Florian Schmaus
|
||||
* Copyright 2014-2018 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -263,6 +263,25 @@ public class ArrayBlockingQueueWithShutdown<E> extends AbstractQueue<E> implemen
|
|||
}
|
||||
}
|
||||
|
||||
public boolean tryPut(E e) {
|
||||
checkNotNull(e);
|
||||
|
||||
boolean locked = lock.tryLock();
|
||||
if (!locked) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
if (isShutdown || isFull()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
insert(e);
|
||||
return true;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException {
|
||||
checkNotNull(e);
|
||||
|
|
Loading…
Reference in a new issue