mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 06:12:05 +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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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
|
@Override
|
||||||
public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException {
|
public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException {
|
||||||
checkNotNull(e);
|
checkNotNull(e);
|
||||||
|
|
Loading…
Reference in a new issue