当前位置: 首页>>代码示例>>Java>>正文


Java ReentrantLock.unlock方法代码示例

本文整理汇总了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 ();
   }
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:27,代码来源:FairQueue.java

示例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();
    }
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:19,代码来源:FixedQueue.java

示例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();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:LinkedBlockingQueue.java

示例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();
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:18,代码来源:FairLinkedBlockingDeque.java

示例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();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:ArrayBlockingQueue.java

示例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();
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:21,代码来源:LinkedBlockingDeque.java

示例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();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:LinkedBlockingDeque.java

示例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();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:ScheduledThreadPoolExecutor.java

示例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();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:14,代码来源:CopyOnWriteArrayList.java

示例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();
    }
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:15,代码来源:LinkedBlockingDeque.java

示例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();
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:12,代码来源:LinkedBlockingDeque.java

示例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;
}
 
开发者ID:retrostreams,项目名称:android-retrostreams,代码行数:37,代码来源:LBDSpliterator.java

示例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();
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:11,代码来源:LinkedBlockingDeque.java

示例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();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:CopyOnWriteArrayList.java

示例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();
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:14,代码来源:FairBlockingQueue.java


注:本文中的java.util.concurrent.locks.ReentrantLock.unlock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。