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


Java BlockingQueue.size方法代碼示例

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


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

示例1: rejectedExecution

import java.util.concurrent.BlockingQueue; //導入方法依賴的package包/類
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("tccTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (runnable instanceof RejectedRunnable) {
        ((RejectedRunnable) runnable).rejected();
    } else {
        if (!executor.isShutdown()) {
            BlockingQueue<Runnable> queue = executor.getQueue();
            int discardSize = queue.size() >> 1;
            for (int i = 0; i < discardSize; i++) {
                queue.poll();
            }

            try {
                queue.put(runnable);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
 
開發者ID:yu199195,項目名稱:happylifeplat-tcc,代碼行數:25,代碼來源:RejectedPolicy.java

示例2: rejectedExecution

import java.util.concurrent.BlockingQueue; //導入方法依賴的package包/類
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("txTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (runnable instanceof RejectedRunnable) {
        ((RejectedRunnable) runnable).rejected();
    } else {
        if (!executor.isShutdown()) {
            BlockingQueue<Runnable> queue = executor.getQueue();
            int discardSize = queue.size() >> 1;
            for (int i = 0; i < discardSize; i++) {
                queue.poll();
            }

            try {
                queue.put(runnable);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
 
開發者ID:yu199195,項目名稱:happylifeplat-transaction,代碼行數:25,代碼來源:RejectedPolicy.java

示例3: rejectedExecution

import java.util.concurrent.BlockingQueue; //導入方法依賴的package包/類
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("MythTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (runnable instanceof RejectedRunnable) {
        ((RejectedRunnable) runnable).rejected();
    } else {
        if (!executor.isShutdown()) {
            BlockingQueue<Runnable> queue = executor.getQueue();
            int discardSize = queue.size() >> 1;
            for (int i = 0; i < discardSize; i++) {
                queue.poll();
            }

            try {
                queue.put(runnable);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
 
開發者ID:yu199195,項目名稱:myth,代碼行數:25,代碼來源:RejectedPolicy.java

示例4: rejectedExecution

import java.util.concurrent.BlockingQueue; //導入方法依賴的package包/類
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("txTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (!executor.isShutdown()) {
        BlockingQueue<Runnable> queue = executor.getQueue();
        int discardSize = queue.size() >> 1;
        for (int i = 0; i < discardSize; i++) {
            queue.poll();
        }
        queue.offer(runnable);
    }
}
 
開發者ID:yu199195,項目名稱:happylifeplat-transaction,代碼行數:16,代碼來源:DiscardedPolicy.java

示例5: getFirstNonEmptyQueue

import java.util.concurrent.BlockingQueue; //導入方法依賴的package包/類
/**
 * Returns the first non-empty queue with equal or lesser priority
 * than <i>startIdx</i>. Wraps around, searching a maximum of N
 * queues, where N is this.queues.size().
 *
 * @param startIdx the queue number to start searching at
 * @return the first non-empty queue with less priority, or null if
 * everything was empty
 */
private BlockingQueue<E> getFirstNonEmptyQueue(int startIdx) {
  final int numQueues = this.queues.size();
  for(int i=0; i < numQueues; i++) {
    int idx = (i + startIdx) % numQueues; // offset and wrap around
    BlockingQueue<E> queue = this.queues.get(idx);
    if (queue.size() != 0) {
      return queue;
    }
  }

  // All queues were empty
  return null;
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:23,代碼來源:FairCallQueue.java

示例6: rejectedExecution

import java.util.concurrent.BlockingQueue; //導入方法依賴的package包/類
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("tccTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }
    if (!executor.isShutdown()) {
        BlockingQueue<Runnable> queue = executor.getQueue();
        int discardSize = queue.size() >> 1;
        for (int i = 0; i < discardSize; i++) {
            queue.poll();
        }
        queue.offer(runnable);
    }
}
 
開發者ID:yu199195,項目名稱:happylifeplat-tcc,代碼行數:15,代碼來源:DiscardedPolicy.java

示例7: rejectedExecution

import java.util.concurrent.BlockingQueue; //導入方法依賴的package包/類
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("MythTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }
    if (!executor.isShutdown()) {
        BlockingQueue<Runnable> queue = executor.getQueue();
        int discardSize = queue.size() >> 1;
        for (int i = 0; i < discardSize; i++) {
            queue.poll();
        }
        queue.offer(runnable);
    }
}
 
開發者ID:yu199195,項目名稱:myth,代碼行數:15,代碼來源:DiscardedPolicy.java

示例8: getThrottledVirtualSpoutIdentifiers

import java.util.concurrent.BlockingQueue; //導入方法依賴的package包/類
/**
 * Internal method used *ONLY* within tests.  Hacky implementation -- could have race-conditions in other use-cases.
 * @return Set of all VirtualSpoutIds that ARE throttled.
 */
Set<VirtualSpoutIdentifier> getThrottledVirtualSpoutIdentifiers() {
    Set<VirtualSpoutIdentifier> throttledVirtualSpoutIds = new HashSet<>();

    for (Map.Entry<VirtualSpoutIdentifier, BlockingQueue<Message>> entry: messageBuffer.entrySet()) {
        BlockingQueue<Message> queue = entry.getValue();
        if (queue.remainingCapacity() + queue.size() == getThrottledBufferSize()) {
            throttledVirtualSpoutIds.add(entry.getKey());
        }
    }
    return throttledVirtualSpoutIds;
}
 
開發者ID:salesforce,項目名稱:storm-dynamic-spout,代碼行數:16,代碼來源:ThrottledMessageBuffer.java

示例9: getNonThrottledVirtualSpoutIdentifiers

import java.util.concurrent.BlockingQueue; //導入方法依賴的package包/類
/**
 * Internal method used *ONLY* within tests.  Hacky implementation -- could have race-conditions in other use-cases.
 * @return Set of all VirtualSpoutIds that are NOT throttled.
 */
Set<VirtualSpoutIdentifier> getNonThrottledVirtualSpoutIdentifiers() {
    Set<VirtualSpoutIdentifier> nonThrottledVirtualSpoutIds = new HashSet<>();

    for (Map.Entry<VirtualSpoutIdentifier, BlockingQueue<Message>> entry: messageBuffer.entrySet()) {
        BlockingQueue<Message> queue = entry.getValue();
        if (queue.remainingCapacity() + queue.size() > getThrottledBufferSize()) {
            nonThrottledVirtualSpoutIds.add(entry.getKey());
        }
    }
    return nonThrottledVirtualSpoutIds;
}
 
開發者ID:salesforce,項目名稱:storm-dynamic-spout,代碼行數:16,代碼來源:ThrottledMessageBuffer.java

示例10: getQueueLength

import java.util.concurrent.BlockingQueue; //導入方法依賴的package包/類
@Override
public int getQueueLength() {
  int length = 0;
  for (final BlockingQueue<CallRunner> queue : queues) {
    length += queue.size();
  }
  return length;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:9,代碼來源:BalancedQueueRpcExecutor.java

示例11: getQueueLength

import java.util.concurrent.BlockingQueue; //導入方法依賴的package包/類
@Override
public int getQueueLength() {
  int length = 0;
  for (final BlockingQueue<CallRunner> queue: queues) {
    length += queue.size();
  }
  return length;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:9,代碼來源:RWQueueRpcExecutor.java

示例12: close

import java.util.concurrent.BlockingQueue; //導入方法依賴的package包/類
/**
 * Closes the pool and all disconnects all idle connections
 * Active connections will be closed upon the {@link java.sql.Connection#close close} method is called
 * on the underlying connection instead of being returned to the pool
 * @param force - true to even close the active connections
 */
protected void close(boolean force) {
    //are we already closed
    if (this.closed) return;
    //prevent other threads from entering
    this.closed = true;
    //stop background thread
    if (poolCleaner!=null) {
        poolCleaner.stopRunning();
    }

    /* release all idle connections */
    BlockingQueue<PooledConnection> pool = (idle.size()>0)?idle:(force?busy:idle);
    while (pool.size()>0) {
        try {
            //retrieve the next connection
            PooledConnection con = pool.poll(1000, TimeUnit.MILLISECONDS);
            //close it and retrieve the next one, if one is available
            while (con != null) {
                //close the connection
                if (pool==idle)
                    release(con);
                else
                    abandon(con);
                if (pool.size()>0) {
                    con = pool.poll(1000, TimeUnit.MILLISECONDS);
                } else {
                    break;
                }
            } //while
        } catch (InterruptedException ex) {
            if (getPoolProperties().getPropagateInterruptState()) {
                Thread.currentThread().interrupt();
            }
        }
        if (pool.size()==0 && force && pool!=busy) pool = busy;
    }
    if (this.getPoolProperties().isJmxEnabled()) this.jmxPool = null;
    PoolProperties.InterceptorDefinition[] proxies = getPoolProperties().getJdbcInterceptorsAsArray();
    for (int i=0; i<proxies.length; i++) {
        try {
            JdbcInterceptor interceptor = proxies[i].getInterceptorClass().newInstance();
            interceptor.setProperties(proxies[i].getProperties());
            interceptor.poolClosed(this);
        }catch (Exception x) {
            log.debug("Unable to inform interceptor of pool closure.",x);
        }
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:55,代碼來源:ConnectionPool.java

示例13: saturatedSize

import java.util.concurrent.BlockingQueue; //導入方法依賴的package包/類
/**
 * Returns maximum number of tasks that can be submitted to given
 * pool (with bounded queue) before saturation (when submission
 * throws RejectedExecutionException).
 */
static final int saturatedSize(ThreadPoolExecutor pool) {
    BlockingQueue<Runnable> q = pool.getQueue();
    return pool.getMaximumPoolSize() + q.size() + q.remainingCapacity();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:10,代碼來源:JSR166TestCase.java


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