1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-22 20:47:57 +01:00

Add ArrayBlockingQueueWithShutdown.tryPut(E)

This commit is contained in:
Florian Schmaus 2018-05-16 07:57:50 +02:00
parent 59ac41faef
commit c7697ea9d0

View file

@ -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);