本文整理汇总了Java中java.util.concurrent.atomic.AtomicInteger.getAndDecrement方法的典型用法代码示例。如果您正苦于以下问题:Java AtomicInteger.getAndDecrement方法的具体用法?Java AtomicInteger.getAndDecrement怎么用?Java AtomicInteger.getAndDecrement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.atomic.AtomicInteger
的用法示例。
在下文中一共展示了AtomicInteger.getAndDecrement方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: poll
import java.util.concurrent.atomic.AtomicInteger; //导入方法依赖的package包/类
public E poll() {
final AtomicInteger count = this.count;
if (count.get() == 0)
return null;
E x = null;
int c = -1;
final ReentrantLock takeLock = this.takeLock;
takeLock.lock();
try {
if (count.get() > 0) {
x = dequeue();
c = count.getAndDecrement();
if (c > 1)
notEmpty.signal();
}
} finally {
takeLock.unlock();
}
if (c == capacity)
signalNotFull();
return x;
}
示例2: poll
import java.util.concurrent.atomic.AtomicInteger; //导入方法依赖的package包/类
public E poll() {
final AtomicInteger count = this.count;
if (count.get() == 0)
return null;
E x = null;
int c = -1;
final ReentrantLock takeLock = this.takeLock;
takeLock.lock();
try {
if (count.get() > 0) {
x = extract();
c = count.getAndDecrement();
if (c > 1)
notEmpty.signal();
}
} finally {
takeLock.unlock();
}
if (c == capacity)
signalNotFull();
return x;
}
示例3: poll
import java.util.concurrent.atomic.AtomicInteger; //导入方法依赖的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 = opQueue(null);
c = count.getAndDecrement();
if (c > 1) notEmpty.signal();
} finally {
takeLock.unlock();
}
if (c == capacity) signalNotFull();
return x;
}
示例4: take
import java.util.concurrent.atomic.AtomicInteger; //导入方法依赖的package包/类
public E take() throws InterruptedException {
E x;
int c = -1;
final AtomicInteger count = this.count;
final ReentrantLock takeLock = this.takeLock;
takeLock.lockInterruptibly();
try {
try {
while (count.get() == 0)
notEmpty.await();
} catch (InterruptedException ie) {
notEmpty.signal(); // propagate to a non-interrupted thread
throw ie;
}
x = extract();
c = count.getAndDecrement();
if (c > 1)
notEmpty.signal();
} finally {
takeLock.unlock();
}
if (c == capacity)
signalNotFull();
return x;
}
示例5: take
import java.util.concurrent.atomic.AtomicInteger; //导入方法依赖的package包/类
/** 从队列头部获取元素, size为空时等待
* @throws InterruptedException */
public E take() throws InterruptedException {
E x;
int c = -1;
final AtomicInteger count = this.size;
final ReentrantLock takeLock = this.takeLock;
takeLock.lockInterruptibly();
try {
while (count.get() == 0) {
notEmpty.await();
}
x = super.poll();
c = count.getAndDecrement();
if (c > 1)
notEmpty.signal();
} finally {
takeLock.unlock();
}
if (c == Integer.MAX_VALUE)
signalNotFull();
return x;
}
示例6: take
import java.util.concurrent.atomic.AtomicInteger; //导入方法依赖的package包/类
public E take() throws InterruptedException {
E x;
int c = -1;
final AtomicInteger count = this.count;
final ReentrantLock takeLock = this.takeLock;
takeLock.lockInterruptibly();
try {
while (count.get() == 0) {
notEmpty.await();
}
x = dequeue();
c = count.getAndDecrement();
if (c > 1)
notEmpty.signal();
} finally {
takeLock.unlock();
}
if (c == capacity)
signalNotFull();
return x;
}
示例7: poll
import java.util.concurrent.atomic.AtomicInteger; //导入方法依赖的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;
}
示例8: take
import java.util.concurrent.atomic.AtomicInteger; //导入方法依赖的package包/类
public E take() throws InterruptedException {
E x;
int c = -1;
final AtomicInteger count = this.count;
final ReentrantLock takeLock = this.takeLock;
takeLock.lockInterruptibly();
try {
while (count.get() == 0) {
notEmpty.await();
}
x = dequeue();
c = count.getAndDecrement();
if (c > 1)
notEmpty.signal();
} finally {
takeLock.unlock();
}
if (c == capacity)
signalNotFull();
return x;
}
示例9: poll
import java.util.concurrent.atomic.AtomicInteger; //导入方法依赖的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;
}
示例10: take
import java.util.concurrent.atomic.AtomicInteger; //导入方法依赖的package包/类
@Override
public E take () throws InterruptedException
{
E x;
int c = -1;
final AtomicInteger count = this.count;
final ReentrantLock takeLock = this.takeLock;
takeLock.lockInterruptibly ();
try
{
while (count.get () == 0)
{
notEmpty.await ();
}
x = getNext (true);
c = count.getAndDecrement ();
if (c > 1)
{
notEmpty.signal ();
}
}
finally
{
takeLock.unlock ();
}
return x;
}
示例11: poll
import java.util.concurrent.atomic.AtomicInteger; //导入方法依赖的package包/类
@Override
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 = getNext (true);
c = count.getAndDecrement ();
if (c > 1)
{
notEmpty.signal ();
}
}
finally
{
takeLock.unlock ();
}
return x;
}