@Scheduled与cron表达式突然停止工作

时间:2018-04-09 23:34:17

标签: java spring cron scheduled-tasks

我知道这个问题会重演,但我已经尝试了所有的建议而没有任何效果。 我使用的是弹簧1.4.3。 我使用弹性beanstalk,这样我的开发EC2实例类型:t2.small与prod是EC2实例类型:t2.large

我正在尝试工作直到今天并突然停止而没有错误或任何事情......(不仅这项工作是我项目中的所有工作)

我的配置是:

  @Configuration
 @EnableAsync
 @EnableScheduling
  public class AppConfig{

  @Bean(destroyMethod = "shutdown")
public Executor taskScheduler() {
    return Executors.newScheduledThreadPool(5);
   }
} 

我尝试的工作非常简单:

 @Service
open class TestProcessing {
private val logger = LoggerFactory.getLogger(this.javaClass)
@Scheduled(fixedDelay = 5000)
fun startProcessing2(){
        logger.info("Test2 Job")
     }

 }

我的主要是:

  @SpringBootApplication(exclude = EndpointMBeanExportAutoConfiguration.class)
  public class ApiServerApplication {

public static void main(String[] args) {
    new SpringApplicationBuilder(ApiServerApplication.class).run(args);
   }
}

帖子请求:

     @ResponseBody
     @RequestMapping(
  path = arrayOf("", "/"),
  method = arrayOf(RequestMethod.POST),
  consumes = arrayOf(MediaType.APPLICATION_JSON_UTF8_VALUE))
    fun insertDispenserRecordsList(@RequestHeader(name = "xg-BAddress", required = false) reporter: String?,
                             @Valid @RequestBody dispenserRecords: DispenserRecordsList<DispenserRecordInput>,
                             bindingResult: BindingResult): ResponseEntity<*> {
        if (bindingResult.hasErrors()) {
        throw exception(bindingResult)
          }
        dispenserRecordsService.insertDispenserRecordsList(reporter, dispenserRecords.dispenserRecords)
       return ResponseEntity<Any>(HttpStatus.OK)

}

有趣的是,工作正在制作和本地而不是开发,他们之间的不同之处在于开发每秒都有一个帖子请求...... 它看起来像这样:

    2018-04-09 23:29:17.080  WARN 22763 --- [io-8080-exec-53] c.h.u.q.RequestStatisticsInterceptor     : [Time: 454 ms] [Queries: 3] POST /v1/dispensers/records
    2018-04-09 23:29:17.316  WARN 22763 --- [io-8080-exec-49] c.h.u.q.RequestStatisticsInterceptor     : [Time: 213 ms] [Queries: 3] POST /v1/wristbands/records
    2018-04-09 23:29:20.396  WARN 22763 --- [nio-8080-exec-3] c.h.u.q.RequestStatisticsInterceptor     : [Time: 180 ms] [Queries: 3] POST /v1/wristbands/records
    2018-04-09 23:29:21.115  WARN 22763 --- [io-8080-exec-30] c.h.u.q.RequestStatisticsInterceptor     : [Time: 206 ms] [Queries: 3] POST /v1/wristbands/records
    2018-04-09 23:29:21.284  WARN 22763 --- [io-8080-exec-33] c.h.u.q.RequestStatisticsInterceptor     : [Time: 215 ms] [Queries: 3] POST /v1/wristbands/records
    2018-04-09 23:29:21.927  WARN 22763 --- [io-8080-exec-61] c.h.u.q.RequestStatisticsInterceptor     : [Time: 251 ms] [Queries: 3] POST /v1/wristbands/records
    2018-04-09 23:29:22.667  WARN 22763 --- [nio-8080-exec-9] c.h.u.q.RequestStatisticsInterceptor     : [Time: 159 ms] [Queries: 3] POST /v1/wristbands/records
    2018-04-09 23:29:25.203  WARN 22763 --- [io-8080-exec-44] c.h.u.q.RequestStatisticsInterceptor     : [Time: 265 ms] [Queries: 3] POST /v1/wristbands/records
    2018-04-09 23:29:27.754  WARN 22763 --- [io-8080-exec-28] c.h.u.q.RequestStatisticsInterceptor     : [Time: 213 ms] [Queries: 4] POST /v1/wristbands/records
    2018-04-09 23:29:28.160  WARN 22763 --- [io-8080-exec-64] c.h.u.q.RequestStatisticsInterceptor     : [Time: 219 ms] [Queries: 3] POST /v1/wristbands/records
    2018-04-09 23:29:31.733  WARN 22763 --- [io-8080-exec-13] c.h.u.q.RequestStatisticsInterceptor     : [Time: 189 ms] [Queries: 3] POST /v1/wristbands/records
    2018-04-09 23:29:32.212  WARN 22763 --- [io-8080-exec-37] c.h.u.q.RequestStatisticsInterceptor     : [Time: 363 ms] [Queries: 3] POST /v1/wristbands/records
    2018-04-09 23:29:35.390  WARN 22763 --- [io-8080-exec-12] c.h.u.q.RequestStatisticsInterceptor     : [Time: 374 ms] [Queries: 3] POST /v1/wristbands/records
    2018-04-09 23:29:36.167  WARN 22763 --- [io-8080-exec-59] c.h.u.q.RequestStatisticsInterceptor     : [Time: 174 ms] [Queries: 3] POST /v1/wristbands/records
    2018-04-09 23:29:37.918  WARN 22763 --- [io-8080-exec-34] c.h.u.q.RequestStatisticsInterceptor     : [Time: 188 ms] [Queries: 3] POST /v1/wristbands/records
    2018-04-09 23:29:41.144  WARN 22763 --- [io-8080-exec-24] c.h.u.q.RequestStatisticsInterceptor     : [Time: 199 ms] [Queries: 3] POST /v1/wristbands/records
    2018-04-09 23:29:43.337  WARN 22763 --- [io-8080-exec-34] c.h.u.q.RequestStatisticsInterceptor     : [Time: 192 ms] [Queries: 3] POST /v1/wristbands/records
    2018-04-09 23:29:44.361  WARN 22763 --- [io-8080-exec-48] c.h.u.q.RequestStatisticsInterceptor     : [Time: 176 ms] [Queries: 3] POST /v1/wristbands/records
    2018-04-09 23:29:45.624  WARN 22763 --- [nio-8080-exec-7] c.h.u.q.RequestStatisticsInterceptor     : [Time: 352 ms] [Queries: 3] POST /v1/wristbands/records
    2018-04-09 23:29:46.094  WARN 22763 --- [io-8080-exec-37] c.h.u.q.RequestStatisticsInterceptor     : [Time: 186 ms] [Queries: 3] POST /v1/wristbands/records

如果您需要更多详情,请告诉我们...... 谢谢你的帮助

1 个答案:

答案 0 :(得分:1)

情况指出,因为开发人员每个POST请求都在执行某项任务或调用等待其响应的任何其他外部系统。 一种可能的解决方案是为POST请求定义超时,该超时应小于@Sceduled时间。 我对POST请求有同样的问题,它从DB获取记录列表。

REPLACE({Table.ItemDescription}, "Black Feet", "Romano Chair")

等待服务响应。在您的情况下,POST请求必须异步等待响应,否则它不能在Prod或Local中运行。