Spring Scheduler stops unexpectedly

前端 未结 3 448
孤城傲影
孤城傲影 2020-12-13 02:02

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 s

3条回答
  •  萌比男神i
    2020-12-13 02:57

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

    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
    

    to 30 seconds the problem was gone.

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

提交回复
热议问题