Spring Scheduler意外停止 [英] Spring Scheduler stops unexpectedly

查看:363
本文介绍了Spring Scheduler意外停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在Tomcat 6上有一个Spring 3 Web应用程序,它通过 @Scheduled 使用多个预定服务(主要用于每晚运行的作业)。现在似乎有时(很少,也许在两个月左右)调度程序线程停止工作,因此在第二天晚上不会执行任何作业。我们的日志文件中没有异常或日志条目。

We have a Spring 3 web application on Tomcat 6 that uses several scheduled services via @Scheduled (mainly for jobs that run every night). Now it appears that sometimes (rarely, perhaps once in two months or so) the scheduler thread stops working, so none of the jobs will be executed in the following night. There is no exception or logging entry in our log files.

有人知道为什么会这样吗?或者如何获得有关此问题的更多信息?

Has anybody a clue why this is happening? Or how to get more information about this problem?

有没有办法在应用程序中检测这种情况并重新启动调度程序?

Is there a way to detect this situation within the application and to restart the scheduler?

目前,我们通过每5分钟运行一次日志记录作业并创建日志条目来解决这个问题。如果日志文件停止更新(由nagios监控),我们知道是时候重启tomcat了。如果没有完整的服务器重启,重新启动作业会很好。

Currently we are solving this by having also a logging job that runs every 5 minutes and creates a log entry. If the log file stops being updated (monitored by nagios), we know it is time to restart tomcat. It would be nice to restart the jobs without a complete server restart.

推荐答案

由于这个问题获得了如此多的选票,我会发布我的问题的(可能是非常具体的)解决方案。

Since this question got so many votes, I'll post what the (probably very specific) solution to my problem was.

我们正在使用Apache HttpClient库来调用预定作业中的远程服务。不幸的是,执行请求时没有设置默认超时。设置后

We are using the Apache HttpClient library to make calls to remote services in the scheduled jobs. Unfortunately there are no default timeouts set when performing requests. After setting

connectTimeout
connectionRequestTimeout
socketTimeout

30秒问题消失。

int timeout = 30 * 1000; // 30 seconds
RequestConfig requestConfig = RequestConfig.custom()
        .setConnectTimeout(timeout)
        .setConnectionRequestTimeout(timeout)
        .setSocketTimeout(timeout).build();
HttpClient client = HttpClients.custom()
        .setDefaultRequestConfig(requestConfig).build();

这篇关于Spring Scheduler意外停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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