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


Java AtomicInteger.decrementAndGet方法代碼示例

本文整理匯總了Java中java.util.concurrent.atomic.AtomicInteger.decrementAndGet方法的典型用法代碼示例。如果您正苦於以下問題:Java AtomicInteger.decrementAndGet方法的具體用法?Java AtomicInteger.decrementAndGet怎麽用?Java AtomicInteger.decrementAndGet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.concurrent.atomic.AtomicInteger的用法示例。


在下文中一共展示了AtomicInteger.decrementAndGet方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: connect

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
public void connect(final String webSocketServerUrl, final JSExecutorConnectCallback callback) {
  final AtomicInteger retryCount = new AtomicInteger(CONNECT_RETRY_COUNT);
  final JSExecutorConnectCallback retryProxyCallback = new JSExecutorConnectCallback() {
    @Override
    public void onSuccess() {
      callback.onSuccess();
    }

    @Override
    public void onFailure(Throwable cause) {
      if (retryCount.decrementAndGet() <= 0) {
        callback.onFailure(cause);
      } else {
        connectInternal(webSocketServerUrl, this);
      }
    }
  };
  connectInternal(webSocketServerUrl, retryProxyCallback);
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:20,代碼來源:WebsocketJavaScriptExecutor.java

示例2: disposeRace

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
@Test
public void disposeRace() {
    ExecutorService exec = Executors.newSingleThreadExecutor();
    final Scheduler s = Schedulers.from(exec);
    try {
        for (int i = 0; i < 500; i++) {
            final Worker w = s.createWorker();

            final AtomicInteger c = new AtomicInteger(2);

            w.schedule(new Runnable() {
                @Override
                public void run() {
                    c.decrementAndGet();
                    while (c.get() != 0) { }
                }
            });

            c.decrementAndGet();
            while (c.get() != 0) { }
            w.dispose();
        }
    } finally {
        exec.shutdownNow();
    }
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:27,代碼來源:ExecutorSchedulerTest.java

示例3: testSubmitTrue

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
@Test
public void testSubmitTrue() throws IOException {
  final AsyncProcess ap = new MyAsyncProcess(createHConnection(), conf, false);
  ap.tasksInProgress.incrementAndGet();
  final AtomicInteger ai = new AtomicInteger(1);
  ap.taskCounterPerRegion.put(hri1.getRegionName(), ai);

  final AtomicBoolean checkPoint = new AtomicBoolean(false);
  final AtomicBoolean checkPoint2 = new AtomicBoolean(false);

  Thread t = new Thread(){
    @Override
    public void run(){
      Threads.sleep(1000);
      Assert.assertFalse(checkPoint.get()); // TODO: this is timing-dependent
      ai.decrementAndGet();
      ap.tasksInProgress.decrementAndGet();
      checkPoint2.set(true);
    }
  };

  List<Put> puts = new ArrayList<Put>();
  Put p = createPut(1, true);
  puts.add(p);

  ap.submit(DUMMY_TABLE, puts, false, null, false);
  Assert.assertFalse(puts.isEmpty());

  t.start();

  ap.submit(DUMMY_TABLE, puts, true, null, false);
  Assert.assertTrue(puts.isEmpty());

  checkPoint.set(true);
  while (!checkPoint2.get()){
    Threads.sleep(1);
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:39,代碼來源:TestAsyncProcess.java

示例4: findFreeSession

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
private Session findFreeSession() {
    for (Entry<Session, AtomicInteger> entry : sessions.entrySet()) {
        Session s = entry.getKey();
        AtomicInteger availableChannels = entry.getValue();
        if (s.isConnected() && availableChannels.get() > 0) {
            log.log(Level.FINE, "availableChannels == {0}", new Object[]{availableChannels.get()}); // NOI18N
            int remains = availableChannels.decrementAndGet();
            log.log(Level.FINE, "Reuse session [{0}]. {1} channels remain...", new Object[]{System.identityHashCode(s), remains}); // NOI18N
            return s;
        }
    }

    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:15,代碼來源:JSchChannelsSupport.java

示例5: testScheduleFixedRateOnMultiThreadPoolDoesNotCauseConcurrentExecution

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
public void testScheduleFixedRateOnMultiThreadPoolDoesNotCauseConcurrentExecution() throws Exception {
    final AtomicInteger val = new AtomicInteger(0);
    final CountDownLatch latch = new CountDownLatch(10);
    class C implements Runnable {
        boolean failed;
        @Override
        public void run() {
            try {
                int now = val.incrementAndGet();
                if (now > 1) {
                    failed = true;
                    fail (now + " threads simultaneously in run()");
                }
                try {
                    //Intentionally sleep *longer* than the interval
                    //between executions.  We *want* to pile up all of the
                    //RP threads entering run() - synchronization should
                    //serialize them.  This test is to prove that this
                    //method will never be called concurrently from two threads
                    Thread.sleep(1000);
                } catch (InterruptedException ex) {

                }
            } finally {
                val.decrementAndGet();
                latch.countDown();
            }
        }
    }
    C c = new C();
    long initialDelay = 2000;
    long period = 10;
    RequestProcessor rp = new RequestProcessor("testScheduleFixedRateOnMultiThreadPoolDoesNotCauseConcurrentExecution", 10, true);
    rp.scheduleAtFixedRate(c, initialDelay, period, TimeUnit.MILLISECONDS);
    latch.await();
    assertFalse(c.failed);
    rp.stop();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:39,代碼來源:RequestProcessor180386Test.java

示例6: start

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
public void start() {
    if (scrollId.getContext().length == 0) {
        listener.onFailure(new SearchPhaseExecutionException("query", "no nodes to search on", ShardSearchFailure.EMPTY_ARRAY));
        return;
    }
    final AtomicInteger counter = new AtomicInteger(scrollId.getContext().length);

    ScrollIdForNode[] context = scrollId.getContext();
    for (int i = 0; i < context.length; i++) {
        ScrollIdForNode target = context[i];
        DiscoveryNode node = nodes.get(target.getNode());
        if (node != null) {
            executeQueryPhase(i, counter, node, target.getScrollId());
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("Node [" + target.getNode() + "] not available for scroll request [" + scrollId.getSource() + "]");
            }
            successfulOps.decrementAndGet();
            if (counter.decrementAndGet() == 0) {
                try {
                    executeFetchPhase();
                } catch (Throwable e) {
                    listener.onFailure(new SearchPhaseExecutionException("query", "Fetch failed", e, ShardSearchFailure.EMPTY_ARRAY));
                    return;
                }
            }
        }
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:30,代碼來源:SearchScrollQueryThenFetchAsyncAction.java

示例7: decrementFileID

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
@Override
protected void decrementFileID(int fileID) {
  AtomicInteger counter = logFileIDReferenceCounts.get(fileID);
  Preconditions.checkState(counter != null, "null counter ");
  int count = counter.decrementAndGet();
  if (count == 0) {
    logFileIDReferenceCounts.remove(fileID);
  }
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:10,代碼來源:EventQueueBackingStoreFile.java

示例8: removeFromReplica

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
private static void removeFromReplica(
    Map<Integer, AtomicInteger> replica, int value) {
  AtomicInteger numOccur = replica.get(value);
  if (numOccur.decrementAndGet() == 0) {
    replica.remove(value);
  }
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:8,代碼來源:MinMaxPriorityQueueTest.java

示例9: callCallback

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
/**
 * 加載本地
 *
 * @param count
 * @param callback
 * @param result
 */
private static void callCallback(final AtomicInteger count, final LoadCallback callback, final Map<String, Drawable> result) {
    synchronized (count) {
        if (count.decrementAndGet() <= 0) {//全部下載完畢的時候回調
            if (callback != null) {
                callback.onLoadResult(result);
            }
        }
    }
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:17,代碼來源:ImageUtil.java

示例10: unrefer

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
/**
 * Unrefer void.
 */
public synchronized void unrefer() {
    if (proxyIns == null) {
        return;
    }
    String key = buildKey();
    LOGGER.info("Unrefer consumer config : {} with bean id {}", key, getId());
    try {
        client.destroy();
    } catch (Exception e) {
        LOGGER.warn("Catch exception when unrefer consumer config : " + key
                + ", but you can ignore if it's called by JVM shutdown hook", e);
    }
    // 清除一些緩存
    AtomicInteger cnt = REFERRED_KEYS.get(key);
    if (cnt != null && cnt.decrementAndGet() <= 0) {
        REFERRED_KEYS.remove(key);
    }
    configListener = null;
    providerListener = null;
    JSFContext.invalidateConsumerConfig(this);
    RpcStatus.removeStatus(this);
    proxyIns = null;

    // 取消訂閱到注冊中心
    unsubscribe();
}
 
開發者ID:tiglabs,項目名稱:jsf-sdk,代碼行數:30,代碼來源:ConsumerConfig.java

示例11: decrementOpenConnections

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
private void decrementOpenConnections(VirtualObject virtualObject) throws DatabaseException {
	AtomicInteger openConnectionCounter = getOpenConnectionCounter(virtualObject.getOid());
	int decrementAndGet = openConnectionCounter.decrementAndGet();
	if (decrementAndGet == 0) {
		deserializer.addVirtualObjectToSave(virtualObject);
	} else if (decrementAndGet < 0) {
		throw new DatabaseException("Inconsistent state");
	}
}
 
開發者ID:shenan4321,項目名稱:BIMplatform,代碼行數:10,代碼來源:WaitingListVirtualObject.java

示例12: main

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException, ExecutionException {
    ExecutorService executorService = Executors.newFixedThreadPool(THREADS_NUMBER);

    CallCounter counter = new CallCounterReadWriteLock();
    AtomicInteger realCountNumber = new AtomicInteger();

    Callable<Integer> callable = () -> {
        while (realCountNumber.getAndIncrement() < HUNDRED_MILLION) {
            counter.increment();
        }
        realCountNumber.decrementAndGet();
        return counter.getCount();
    };

    long startTime = System.currentTimeMillis();


    Future<Integer> future01 = executorService.submit(callable);
    Future<Integer> future02 = executorService.submit(callable);

    System.out.println("Future01: " + future01.get());
    System.out.println("Future02: " + future02.get());
    System.out.println("RealCountNumber: " + realCountNumber);

    long finishTime = System.currentTimeMillis();
    System.out.println("Time spent: " + (finishTime - startTime));
    executorService.shutdown();
}
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_06,代碼行數:29,代碼來源:CounterMain.java

示例13: unregisterConnection

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
public synchronized void unregisterConnection(ConnectContext ctx) {
    if (connectionMap.remove((long) ctx.getConnectionId()) != null) {
        numberConnection--;
        AtomicInteger conns = connByUser.get(ctx.getUser());
        if (conns != null) {
            conns.decrementAndGet();
        }
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:10,代碼來源:ConnectScheduler.java

示例14: emissionRequestRace

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
@Test
public void emissionRequestRace() {
    Worker w = Schedulers.computation().createWorker();
    try {
        for (int i = 0; i < 10000; i++) {

            final TestSubscriber<Integer> ts = TestSubscriber.create(0L);
            TestingDeferredScalarSubscriber ds = new TestingDeferredScalarSubscriber(ts);
            ds.setupDownstream();
            ds.onNext(1);

            final AtomicInteger ready = new AtomicInteger(2);

            w.schedule(new Runnable() {
                @Override
                public void run() {
                    ready.decrementAndGet();
                    while (ready.get() != 0) { }

                    ts.request(1);
                }
            });

            ready.decrementAndGet();
            while (ready.get() != 0) { }

            ds.onComplete();

            ts.awaitTerminalEvent(5, TimeUnit.SECONDS);
            ts.assertValues(1);
            ts.assertNoErrors();
            ts.assertComplete();

        }
    } finally {
        w.dispose();
    }
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:39,代碼來源:DeferredScalarSubscriberTest.java

示例15: tryGetCid

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
private String tryGetCid(Set<String> blackSet) {
    AtomicInteger load;
    String cid = null;
    String tmpCid;
    int times = pieceContainer.size();
    boolean needOffer;
    while (times-- > 0) {
        needOffer = true;
        tmpCid = pieceContainer.peek();

        if (tmpCid == null) {
            pieceHitLogger.info("peek element from empty queue");
            break;
        }
        if (progressRepo.getServiceDownInfo(tmpCid)) {
            needOffer = false;
        } else {
            AtomicInteger errorCount = progressRepo
                .getServiceErrorInfo(tmpCid);
            if (errorCount != null
                && errorCount.get() >= Constants.ELIMINATION_LIMIT) {
                needOffer = false;
            } else {
                if (blackSet == null || !blackSet.contains(tmpCid)) {
                    load = progressRepo.getProducerLoad(tmpCid);
                    if (load != null) {
                        if (load.incrementAndGet() <= Constants.PEER_UP_LIMIT) {
                            cid = tmpCid;
                            break;
                        } else {
                            load.decrementAndGet();
                        }
                    } else {
                        needOffer = false;
                    }
                }
            }
        }
        synchronized (pieceContainer) {
            if (StringUtils.equals(pieceContainer.peek(), tmpCid)) {
                if (pieceContainer.remove(tmpCid) && needOffer) {
                    pieceContainer.offer(tmpCid);
                }
            }
        }

    }

    return cid;
}
 
開發者ID:alibaba,項目名稱:Dragonfly,代碼行數:51,代碼來源:PieceState.java


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