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