当前位置: 首页>>代码示例>>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;未经允许,请勿转载。