當前位置: 首頁>>代碼示例>>Java>>正文


Java AtomicInteger.getAndDecrement方法代碼示例

本文整理匯總了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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:LinkedBlockingQueue.java

示例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;
}
 
開發者ID:nsg-ethz,項目名稱:iTAP-controller,代碼行數:23,代碼來源:PriorityPendingQueue.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:PriorityBlockingQueue.java

示例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;
}
 
開發者ID:nsg-ethz,項目名稱:iTAP-controller,代碼行數:26,代碼來源:PriorityPendingQueue.java

示例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;
}
 
開發者ID:NymphWeb,項目名稱:nymph,代碼行數:24,代碼來源:NyQueue.java

示例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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:22,代碼來源:LinkedBlockingQueue.java

示例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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:LinkedBlockingQueue.java

示例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;
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:22,代碼來源:ForceableLinkedBlockingQueue.java

示例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;
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:25,代碼來源:ForceableLinkedBlockingQueue.java

示例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;
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:28,代碼來源:FairQueue.java

示例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;
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:33,代碼來源:FairQueue.java


注:本文中的java.util.concurrent.atomic.AtomicInteger.getAndDecrement方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。