本文整理汇总了Java中java.util.concurrent.locks.ReentrantLock.unlock方法的典型用法代码示例。如果您正苦于以下问题:Java ReentrantLock.unlock方法的具体用法?Java ReentrantLock.unlock怎么用?Java ReentrantLock.unlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.locks.ReentrantLock
的用法示例。
在下文中一共展示了ReentrantLock.unlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: put
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
@Override
public void put (E e) throws InterruptedException
{
if (e == null)
{
throw new NullPointerException ();
}
int c = -1;
final ReentrantLock putLock = this.putLock;
final AtomicInteger count = this.count;
putLock.lockInterruptibly ();
try
{
store (e);
c = count.getAndIncrement ();
}
finally
{
putLock.unlock ();
}
if (c == 0)
{
signalNotEmpty ();
}
}
示例2: clear
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public void clear() {
final E[] items = this.items;
final ReentrantLock lock = this.lock;
lock.lock();
try {
int i = takeIndex;
int j = count;
while (j-- > 0) {
items[i] = null;
i = inc(i);
}
count = 0;
putIndex = 0;
takeIndex = 0;
} finally {
lock.unlock();
}
}
示例3: LinkedBlockingQueue
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
/**
* Creates a {@code LinkedBlockingQueue} with a capacity of
* {@link Integer#MAX_VALUE}, initially containing the elements of the
* given collection,
* added in traversal order of the collection's iterator.
*
* @param c the collection of elements to initially contain
* @throws NullPointerException if the specified collection or any
* of its elements are null
*/
public LinkedBlockingQueue(Collection<? extends E> c) {
this(Integer.MAX_VALUE);
final ReentrantLock putLock = this.putLock;
putLock.lock(); // Never contended, but necessary for visibility
try {
int n = 0;
for (E e : c) {
if (e == null)
throw new NullPointerException();
if (n == capacity)
throw new IllegalStateException("Queue full");
enqueue(new Node<E>(e));
++n;
}
count.set(n);
} finally {
putLock.unlock();
}
}
示例4: removeFirstOccurrence
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public boolean removeFirstOccurrence(Object o) {
if (o == null)
return false;
final ReentrantLock reentrantLock = this.lock;
reentrantLock.lock();
try {
for (Node<E> p = first; p != null; p = p.next) {
if (o.equals(p.item)) {
unlink(p);
return true;
}
}
return false;
} finally {
reentrantLock.unlock();
}
}
示例5: offer
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
/**
* Inserts the specified element at the tail of this queue if it is
* possible to do so immediately without exceeding the queue's capacity,
* returning {@code true} upon success and {@code false} if this queue
* is full. This method is generally preferable to method {@link #add},
* which can fail to insert an element only by throwing an exception.
*
* @throws NullPointerException if the specified element is null
*/
public boolean offer(E e) {
Objects.requireNonNull(e);
final ReentrantLock lock = this.lock;
lock.lock();
try {
if (count == items.length)
return false;
else {
enqueue(e);
return true;
}
} finally {
lock.unlock();
}
}
示例6: clear
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public void clear() {
ReentrantLock lock = this.lock;
lock.lock();
try {
Node<E> f = this.first;
while (f != null) {
f.item = null;
Node<E> n = f.next;
f.prev = null;
f.next = null;
f = n;
}
this.last = null;
this.first = null;
this.count = 0;
this.notFull.signalAll();
} finally {
lock.unlock();
}
}
示例7: offerLast
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
/**
* @throws NullPointerException {@inheritDoc}
* @throws InterruptedException {@inheritDoc}
*/
public boolean offerLast(E e, long timeout, TimeUnit unit)
throws InterruptedException {
if (e == null) throw new NullPointerException();
Node<E> node = new Node<E>(e);
long nanos = unit.toNanos(timeout);
final ReentrantLock lock = this.lock;
lock.lockInterruptibly();
try {
while (!linkLast(node)) {
if (nanos <= 0)
return false;
nanos = notFull.awaitNanos(nanos);
}
return true;
} finally {
lock.unlock();
}
}
示例8: clear
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public void clear() {
final ReentrantLock lock = this.lock;
lock.lock();
try {
for (int i = 0; i < size; i++) {
RunnableScheduledFuture<?> t = queue[i];
if (t != null) {
queue[i] = null;
setIndex(t, -1);
}
}
size = 0;
} finally {
lock.unlock();
}
}
示例9: subList
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public List<E> subList(int fromIndex, int toIndex) {
final ReentrantLock lock = l.lock;
lock.lock();
try {
checkForComodification();
if (fromIndex < 0 || toIndex > size || fromIndex > toIndex)
throw new IndexOutOfBoundsException();
return new COWSubList<E>(l, fromIndex + offset,
toIndex + offset);
} finally {
lock.unlock();
}
}
示例10: offerLast
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
/**
* @throws NullPointerException {@inheritDoc}
*/
public boolean offerLast(E e) {
if (e == null) throw new NullPointerException();
Node<E> node = new Node<E>(e);
final ReentrantLock lock = this.lock;
lock.lock();
try {
return linkLast(node);
} finally {
lock.unlock();
}
}
示例11: peekLast
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public E peekLast() {
ReentrantLock lock = this.lock;
lock.lock();
try {
E e = this.last == null ? null : this.last.item;
lock.unlock();
return e;
} catch (Throwable th) {
lock.unlock();
}
}
示例12: trySplit
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
@Override
public Spliterator<E> trySplit() {
Object h;
LinkedBlockingDeque<E> q = queue;
if (!exhausted &&
((h = current) != null || (h = getQueueFirst(q)) != null)
&& getNextNode(h) != null) {
int n = batch = Math.min(batch + 1, MAX_BATCH);
Object[] a = new Object[n];
ReentrantLock lock = queueLock;
int i = 0;
Object p = current;
lock.lock();
try {
if (p != null || (p = getQueueFirst(q)) != null)
for (; p != null && i < n; p = succ(p))
if ((a[i] = getNodeItem(p)) != null)
i++;
} finally {
// checkInvariants();
lock.unlock();
}
if ((current = p) == null) {
est = 0L;
exhausted = true;
}
else if ((est -= i) < 0L)
est = 0L;
if (i > 0)
return Spliterators.spliterator
(a, 0, i, (Spliterator.ORDERED |
Spliterator.NONNULL |
Spliterator.CONCURRENT));
}
return null;
}
示例13: pollFirst
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public E pollFirst() {
ReentrantLock lock = this.lock;
lock.lock();
try {
E unlinkFirst = unlinkFirst();
return unlinkFirst;
} finally {
lock.unlock();
}
}
示例14: get
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public E get(int index) {
final ReentrantLock lock = l.lock;
lock.lock();
try {
rangeCheck(index);
checkForComodification();
return l.get(index+offset);
} finally {
lock.unlock();
}
}
示例15: poll
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public E poll() {
final ReentrantLock lock = this.lock;
lock.lock();
try {
return items.poll();
} finally {
lock.unlock();
}
}