Unhandled exceptions with Java scheduled executors

前端 未结 4 1962
情歌与酒
情歌与酒 2020-12-24 13:16

I have the following issue and I would like to know what exactly happens. I am using Java\'s ScheduledExecutorService to run a task every five minutes. It works very well. E

4条回答
  •  生来不讨喜
    2020-12-24 13:59

    If you are using scheduleAtFixedRate() or scheduleAtFixedDelay(), and your task bails out with an exception, that task will not be rescheduled. However, other independent tasks should continue to execute as expected. (See API Docs). If you care that this has happened, you can grab ahold of the ScheduledFuture that is returned and call the get() method. If the underlying task tosses an exception, you'll get it thrown out of the get() method, wrapped in an ExecutionException.

提交回复
热议问题