Spring Scheduler或Spring Batch用于任务?

时间:2021-09-13 02:16:47

Have a task to delete files based on some conditions. This task should run everyday at some time. Should we use Spring Boot and scheduler for this task. Or Spring Batch + Scheduler would be good. Also can this task be parallely processed using partitioning in Spring Batch.

有一项任务是根据某些条件删除文件。这项任务应该每天运行一次。我们应该使用Spring Boot和scheduler来完成这项任务吗?或者Spring Batch + Scheduler会很好。也可以使用Spring Batch中的分区并行处理此任务。

Thanks

2 个解决方案

#1


0  

I am not sure that you even need spring batch here. Spring batch would be useful if you need:

我不确定你在这里甚至需要弹簧批次。如果您需要,Spring批处理将非常有用:

  • handling transactions
  • robustness/restartability of jobs
  • 工作的稳健性/可重启性

For your plain case of deleting files all you could use - some kind of scheduler together with spring integration. For spring integration you will just configure some kind of poller which will trigger deletion of files:

对于您删除文件的简单情况,您可以使用 - 某种调度程序以及spring集成。对于spring集成,您只需配置一些将触发文件删除的轮询器:

@Bean
public PollerMetadata myPoller() {
  return Pollers.cron("cron expression here")
                .get();
}

#2


0  

To solve this problem (without leveraging Spring Batch) you can combine two simple techniques. To execute your task for running once a day in the simplest way I would recommend a simple Spring scheduled task. For doing multiple file operations in parallel, there are parallel streams respective the fork/join framework. Take a look here to get some ideas.

要解决这个问题(不使用Spring Batch),您可以结合使用两种简单的技术。要以最简单的方式执行每天运行一次的任务,我建议使用简单的Spring计划任务。为了并行执行多个文件操作,存在相应的fork / join框架的并行流。看看这里得到一些想法。

#1


0  

I am not sure that you even need spring batch here. Spring batch would be useful if you need:

我不确定你在这里甚至需要弹簧批次。如果您需要,Spring批处理将非常有用:

  • handling transactions
  • robustness/restartability of jobs
  • 工作的稳健性/可重启性

For your plain case of deleting files all you could use - some kind of scheduler together with spring integration. For spring integration you will just configure some kind of poller which will trigger deletion of files:

对于您删除文件的简单情况,您可以使用 - 某种调度程序以及spring集成。对于spring集成,您只需配置一些将触发文件删除的轮询器:

@Bean
public PollerMetadata myPoller() {
  return Pollers.cron("cron expression here")
                .get();
}

#2


0  

To solve this problem (without leveraging Spring Batch) you can combine two simple techniques. To execute your task for running once a day in the simplest way I would recommend a simple Spring scheduled task. For doing multiple file operations in parallel, there are parallel streams respective the fork/join framework. Take a look here to get some ideas.

要解决这个问题(不使用Spring Batch),您可以结合使用两种简单的技术。要以最简单的方式执行每天运行一次的任务,我建议使用简单的Spring计划任务。为了并行执行多个文件操作,存在相应的fork / join框架的并行流。看看这里得到一些想法。