我正在创建一个新线程来检查文件夹中的新文件,然后休眠一段定义的时间。
我的偏好是使用 ScheduledExecutorService,但是,我找不到任何文档来说明这是否等待当前正在运行的任务完成后再开始新的任务。
例如,在下面的代码中;
Integer samplingInterval = 30;
ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(10);
executorService.scheduleAtFixedRate(new WatchAgent(agentInfo),
0,
samplingInterval,
TimeUnit.SECONDS);
如果run()
ofWatchAgent
时间超过 30 秒,是否会在完成之前创建一个新代理?
其次,如果我创建 的实例WatchAgent
,我可以在每次定期运行时继续使用相同的实例吗?