当被拒绝的执行触发时,Java服务停止运行
当被拒绝的执行触发时,Java服务停止运行 我有一个正在运行的mqtt客户端,它充当Android应用程序和MySQL数据库池的桥梁/服务器,当被拒绝的执行触发我的服务停止时,我真想知道为什么 这是我的线程池当被拒绝的执行触发时,Java服务停止运行,java,mysql,mqtt,bonecp,Java,Mysql,Mqtt,Bonecp,当被拒绝的执行触发时,Java服务停止运行 我有一个正在运行的mqtt客户端,它充当Android应用程序和MySQL数据库池的桥梁/服务器,当被拒绝的执行触发我的服务停止时,我真想知道为什么 这是我的线程池 public static ExecutorService threadPool = new ThreadPoolExecutor(10, // core size 30, // max size 10*60, // idle timeout TimeUnit.SE
public static ExecutorService threadPool = new ThreadPoolExecutor(10, // core size
30, // max size
10*60, // idle timeout
TimeUnit.SECONDS,
new ArrayBlockingQueue<Runnable>(20),
factory,
new DiscardPolicy()); // queue with a size
这就是我收到的信息的表现
@Override
public void messageArrived(final String topic, final MqttMessage message) throws Exception {
threadPool.execute(new Runnable(){
void run(){
if(topic.equalsIgnoreCase("something")){} // and code goes on like these
}
// code
});
try{
if(Constants.pendingRunnables.size() > 0){
for(java.util.Map.Entry<ThreadPoolExecutor, Runnable> runner : Constants.pendingRunnables.entrySet()){
// runner.getKey().execute(runner.getValue());
try{
if (!runner.getKey().isShutdown()) {
runner.getValue().run();
Constants.pendingRunnables.remove(runner.getKey());
}
}catch(Exception ex){
}
}
}
}catch(Exception e){}
}
public class DiscardPolicy extends ThreadPoolExecutor.DiscardPolicy{
private static final Logger LOGGER = Logger.getLogger(DiscardPolicy.class);
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
// TODO Auto-generated method stub
super.rejectedExecution(r, e);
Constants.pendingRunnables.put(e, r);
LOGGER.info("Rejected Runnable ");
}
}
一些可运行程序中有mqtt客户机,以便发布响应。
这些服务所做的是运行可运行程序,当异常触发时,我将它们附加到挂起的可运行程序中,以便以后运行它们
我这里少了什么吗?你能检查一下ExecutorService是否应该关闭吗?CallerRunsPoilicy是被拒绝任务的处理程序,它直接在execute方法的调用线程中运行被拒绝的任务,除非executor已关闭,在这种情况下,该任务将被丢弃。是的,我已检查它并捕获异常,但问题仍然存在,我用DiscardPolicy替换了它,以后再运行。我的服务现在正在运行,但我正在等待被拒绝的异常发生。我有没有其他方法来测试被拒绝的异常?我已经将运行时异常捕获放在了可运行程序的REHandler中,这样我也可以捕获运行时异常Runnables@ravindra查看我的编辑