Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ArrayBlockingQueue-每个月的获取队列总是满的_Java_Multithreading_Producer Consumer_Blockingqueue - Fatal编程技术网

Java ArrayBlockingQueue-每个月的获取队列总是满的

Java ArrayBlockingQueue-每个月的获取队列总是满的,java,multithreading,producer-consumer,blockingqueue,Java,Multithreading,Producer Consumer,Blockingqueue,我有一个处理上传图像的生产者消费者 imageQueueSize = 150 imageConsumersNumber = 10 在初始化队列下面: ArrayBlockingQueue<Context> imageQueue = new ArrayBlockingQueue<Context>(imageQueueSize); for (int i = 0; i < imageConsumersNumber; i++) { new Thread(new Q

我有一个处理上传图像的生产者消费者

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();
}
下面是方法运行实现:

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+请求,但每个月都会有一次被卡住。

您是否检查了
executor.execute(上下文)
不会引发异常?它被try-catch包围,但是queue.take()应该正确地从数组中移除头吗?您是捕获
Throwable
还是其他什么?最可能的原因是消费者最终会有例外。一旦没有消费者,队列最终会变满。现在,在您更新问题之后:当异常发生时,您将跳出循环。您应该将
try catch
块放在循环中。确定后,将尝试将其更改为:
while(true){try{Context Context=queue.take();Executor Executor=executsfacade.getExecutor(Context.getContentData().getMimeFamilyType());Executor.execute(Context);}catch(Throwable e){log.error(“运行方法中的异常”),e);}}
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);
        }