可能是RejectedExecutionException的原因 [英] What could be the cause of RejectedExecutionException

查看:792
本文介绍了可能是RejectedExecutionException的原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的tomcat服务器上获得此异常(+ liferay)

I am getting this exception on my tomcat server (+liferay)

java.util.concurrent.RejectedExecutionException

我的课程是这样的:

public class SingleExecutor extends ThreadPoolExecutor {
  public SingleExecutor(){
    super(1, 1,0L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>());
  }

  @Override
  public void execute(Runnable command) {
    if(command instanceof AccessLogInsert){
        AccessLogInsert ali = (AccessLogInsert)command;
        ali.setConn(conn);
        ali.setPs(ps);
    }
    super.execute(command);
  }
}

我在<$ c $行上获得此异常c> super.execute(command);
当队列已满但 LinkedBlockingQueue 大小为2 ^ 31时,可能会发生此错误,我确信没有那么多命令在等待。

I get this exception on the line super.execute(command); This error can occur when the queue is full but the LinkedBlockingQueue size is 2^31, and I am sure that there is no so many command waiting.

在开始时一切都很稳定,但是在我重新部署战争后它开始出现。这个类不是战争的一部分,而是在tomcat / lib的jar中。

At start everything is stable, but after I redeploy a war it starts occuring. This class is not part of the war but in a jar in tomcat/lib.

你知道为什么会发生这种情况以及如何修复它吗?

Do you have any idea why this happend and how to fix it ?

推荐答案

来自 ThreadPoolExecutor JavaDoc

From ThreadPoolExecutor JavaDoc


方法中提交的新任务当 Executor 关闭时,以及 Executor时,将拒绝执行(java.lang.Runnable) 对最大线程和工作队列容量使用有限边界,并且已经饱和。在任何一种情况下,execute方法都会调用 RejectedExecutionHandler的 RejectedExecutionHandler.rejectedExecution(java.lang.Runnable,java.util.concurrent.ThreadPoolExecutor)方法。提供了四种预定义的处理程序策略:

New tasks submitted in method execute(java.lang.Runnable) will be rejected when the Executor has been shut down, and also when the Executor uses finite bounds for both maximum threads and work queue capacity, and is saturated. In either case, the execute method invokes the RejectedExecutionHandler.rejectedExecution(java.lang.Runnable, java.util.concurrent.ThreadPoolExecutor) method of its RejectedExecutionHandler. Four predefined handler policies are provided:


  1. 在默认的 ThreadPoolExecutor.AbortPolicy 中,处理程序在拒绝时抛出运行时 RejectedExecutionException

  2. ThreadPoolExecutor.CallerRunsPolicy 中,调用execute本身的线程运行任务。这提供了一种简单的反馈控制机制,可以降低新任务的提交速度。

  3. ThreadPoolExecutor.DiscardPolicy 中,一项任务简单地删除了无法执行的内容。

  4. ThreadPoolExecutor.DiscardOldestPolicy 中,如果执行程序未关闭,则头部的任务删除工作队列,然后重试执行(可能会再次失败,导致重复执行。)

  1. In the default ThreadPoolExecutor.AbortPolicy, the handler throws a runtime RejectedExecutionException upon rejection.
  2. In ThreadPoolExecutor.CallerRunsPolicy, the thread that invokes execute itself runs the task. This provides a simple feedback control mechanism that will slow down the rate that new tasks are submitted.
  3. In ThreadPoolExecutor.DiscardPolicy, a task that cannot be executed is simply dropped.
  4. In ThreadPoolExecutor.DiscardOldestPolicy, if the executor is not shut down, the task at the head of the work queue is dropped, and then execution is retried (which can fail again, causing this to be repeated.)

它是可以定义和使用其他种类的 RejectedExecutionHandler 类。这样做需要一些小心,特别是当策略被设计为仅在特定容量或排队策略下工作时。

It is possible to define and use other kinds of RejectedExecutionHandler classes. Doing so requires some care especially when policies are designed to work only under particular capacity or queuing policies.

因此可能重新加载war触发器关闭执行者。尝试将相关库放入战争中,以便Tomcat的 ClassLoader 更有可能正确地重新加载你的应用程序。

Presumably therefore, reloading the war triggers a shutdown of the Executor. Try putting the relevant libraries in the war, so that Tomcat's ClassLoader has a better chance of correctly reloading your app.

这篇关于可能是RejectedExecutionException的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆