我有生产者消费者来处理上传图像,
imageQueueSize = 150
imageConsumersNumber = 10
在初始化队列下面:
ArrayBlockingQueue<Context> imageQueue = new ArrayBlockingQueue<Context>(imageQueueSize);
for (int i = 0; i < imageConsumersNumber; i++) {
new Thread(new QueueProcessor(imageQueue,executorsFacade)).start();
}
使用以下:
if (queue.offer(context, queueOfferTimeOut, TimeUnit.SECONDS)) {
//debug info ..
return true;
} else {
log.info("queue {} is full, contentData {} will not be processed", mimeFamilyType,
context);
return false;
}
下面的方法运行实现:
try{
while(true) {
Context context = queue.take();
Executor executor = executorsFacade.getExecutor(context.getContentData()
.getMimeFamilyType());
executor.execute(context);
}
}catch(Exception e){
log.error("Exception in run methoud ",e);
}
每个月一次,我在日志中只会看到“队列图像已满” 有谁知道为什么会这样? 似乎未执行take()方法并且未清除队列。 我可以在日志中看到它成功处理了10K +个请求,但是每个月都会卡住。