本文整理匯總了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;
}