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


Java ReentrantLock.lockInterruptibly方法代码示例

本文整理汇总了Java中java.util.concurrent.locks.ReentrantLock.lockInterruptibly方法的典型用法代码示例。如果您正苦于以下问题:Java ReentrantLock.lockInterruptibly方法的具体用法?Java ReentrantLock.lockInterruptibly怎么用?Java ReentrantLock.lockInterruptibly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.locks.ReentrantLock的用法示例。


在下文中一共展示了ReentrantLock.lockInterruptibly方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: offerFirst

import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
/**
 * @throws NullPointerException {@inheritDoc}
 * @throws InterruptedException {@inheritDoc}
 */
public boolean offerFirst(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 (!linkFirst(node)) {
            if (nanos <= 0)
                return false;
            nanos = notFull.awaitNanos(nanos);
        }
        return true;
    } finally {
        lock.unlock();
    }
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:23,代码来源:LinkedBlockingDeque.java

示例2: offerFirst

import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
/**
 * @throws NullPointerException {@inheritDoc}
 * @throws InterruptedException {@inheritDoc}
 */
public boolean offerFirst(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 (!linkFirst(node)) {
            if (nanos <= 0)
                return false;
            nanos = notFull.awaitNanos(nanos);
        }
        return true;
    } finally {
        lock.unlock();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:LinkedBlockingDeque.java

示例3: poll

import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public E poll(long timeout, TimeUnit unit) throws InterruptedException {
    E x = null;
    int c = -1;
    long nanos = unit.toNanos(timeout);
    final AtomicInteger count = this.count;
    final ReentrantLock takeLock = this.takeLock;
    takeLock.lockInterruptibly();
    try {
        while (count.get() == 0) {
            if (nanos <= 0)
                return null;
            nanos = notEmpty.awaitNanos(nanos);
        }
        x = dequeue();
        c = count.getAndDecrement();
        if (c > 1)
            notEmpty.signal();
    } finally {
        takeLock.unlock();
    }
    if (c == capacity)
        signalNotFull();
    return x;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:LinkedBlockingQueue.java

示例4: poll

import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public E poll(long timeout, TimeUnit unit) throws InterruptedException {
    E x = null;
    int c = -1;
    long nanos = unit.toNanos(timeout);
    final AtomicInteger count = this.count;
    final ReentrantLock takeLock = this.takeLock;
    takeLock.lockInterruptibly();
    try {
        while (count.get() == 0) {
            if (nanos <= 0L)
                return null;
            nanos = notEmpty.awaitNanos(nanos);
        }
        x = dequeue();
        c = count.getAndDecrement();
        if (c > 1)
            notEmpty.signal();
    } finally {
        takeLock.unlock();
    }
    if (c == capacity)
        signalNotFull();
    return x;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:LinkedBlockingQueue.java

示例5: pollFirst

import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public E pollFirst(long timeout, TimeUnit unit)
    throws InterruptedException {
    long nanos = unit.toNanos(timeout);
    final ReentrantLock lock = this.lock;
    lock.lockInterruptibly();
    try {
        E x;
        while ( (x = unlinkFirst()) == null) {
            if (nanos <= 0)
                return null;
            nanos = notEmpty.awaitNanos(nanos);
        }
        return x;
    } finally {
        lock.unlock();
    }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:18,代码来源:LinkedBlockingDeque.java

示例6: pollFirst

import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public E pollFirst(long timeout, TimeUnit unit)
        throws InterruptedException {
    long nanos = unit.toNanos(timeout);
    final ReentrantLock lock = this.lock;
    lock.lockInterruptibly();
    try {
        E x;
        while ((x = unlinkFirst()) == null) {
            if (nanos <= 0)
                return null;
            nanos = notEmpty.awaitNanos(nanos);
        }
        return x;
    } finally {
        lock.unlock();
    }
}
 
开发者ID:Spencer231,项目名称:GifImageLoader,代码行数:18,代码来源:LinkedBlockingDeque.java

示例7: take

import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
/** Returns the element with the next timestamp, waiting until it is available.
    *
    * <p>Note that because of the reordering semantics, an invocation of this method
    * on a {@linkplain #isEmpty() nonempty} queue might block nonetheless.
    *
    * @return the element with the next timestamp.
    */
public E take() throws InterruptedException {
	final ReentrantLock lock = this.lock;
	lock.lockInterruptibly();
	try {
		while (a[start] == null) nextObjectReady.await();
		@SuppressWarnings("unchecked")
		final E x = (E)a[start];
		a[start] = null;
		start = start + 1 & mask;
		--count;
		timeStamp++;
		newSpaceAvailable.signalAll();
		return x;
	}
	finally {
		lock.unlock();
	}
}
 
开发者ID:LAW-Unimi,项目名称:BUbiNG,代码行数:26,代码来源:ReorderingBlockingQueue.java

示例8: 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

示例9: 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 <= 0L)
                return false;
            nanos = notFull.awaitNanos(nanos);
        }
        return true;
    } finally {
        lock.unlock();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:LinkedBlockingDeque.java

示例10: take

import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
@Override
public T take() throws InterruptedException {
    T x;
    final ReentrantLock takeLock = this.takeLock;
    takeLock.lockInterruptibly();
    try {
        while (size() == 0) {
            notEmpty.await();
        }
        x = poll();
        if (null == x) {
            return take();
        }
        if (size() > 0) {
            notEmpty.signal();
        }
    } finally {
        takeLock.unlock();
    }
    return x;
}
 
开发者ID:nuls-io,项目名称:nuls,代码行数:22,代码来源:PersistentQueue.java

示例11: poll

import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public E poll(long timeout, TimeUnit unit) throws InterruptedException {
    long nanos = unit.toNanos(timeout);
    final ReentrantLock lock = this.lock;
    lock.lockInterruptibly();
    E result;
    try {
        while ( (result = dequeue()) == null && nanos > 0)
            nanos = notEmpty.awaitNanos(nanos);
    } finally {
        lock.unlock();
    }
    return result;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:14,代码来源:PriorityBlockingQueue.java

示例12: poll

import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public E poll(long timeout, TimeUnit unit) throws InterruptedException {
    long nanos = unit.toNanos(timeout);
    final ReentrantLock lock = this.lock;
    lock.lockInterruptibly();
    try {
        while (count == 0) {
            if (nanos <= 0L)
                return null;
            nanos = notEmpty.awaitNanos(nanos);
        }
        return dequeue();
    } finally {
        lock.unlock();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:ArrayBlockingQueue.java

示例13: put

import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
/**
 * Inserts the specified element at the tail of this queue, waiting
 * for space to become available if the queue is full.
 *
 * @throws InterruptedException {@inheritDoc}
 * @throws NullPointerException {@inheritDoc}
 */
public void put(E e) throws InterruptedException {
    checkNotNull(e);
    final ReentrantLock lock = this.lock;
    lock.lockInterruptibly();
    try {
        while (count == items.length)
            notFull.await();
        enqueue(e);
    } finally {
        lock.unlock();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:ArrayBlockingQueue.java

示例14: take

import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public E take() throws InterruptedException {
    final ReentrantLock lock = this.lock;
    lock.lockInterruptibly();
    try {
        while (count == 0)
            notEmpty.await();
        return dequeue();
    } finally {
        lock.unlock();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:ArrayBlockingQueue.java

示例15: take

import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public RunnableScheduledFuture<?> take() throws InterruptedException {
    final ReentrantLock lock = this.lock;
    lock.lockInterruptibly();
    try {
        for (;;) {
            RunnableScheduledFuture<?> first = queue[0];
            if (first == null)
                available.await();
            else {
                long delay = first.getDelay(NANOSECONDS);
                if (delay <= 0)
                    return finishPoll(first);
                first = null; // don't retain ref while waiting
                if (leader != null)
                    available.await();
                else {
                    Thread thisThread = Thread.currentThread();
                    leader = thisThread;
                    try {
                        available.awaitNanos(delay);
                    } finally {
                        if (leader == thisThread)
                            leader = null;
                    }
                }
            }
        }
    } finally {
        if (leader == null && queue[0] != null)
            available.signal();
        lock.unlock();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:34,代码来源:ScheduledThreadPoolExecutor.java


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