Spring Batch-多线程环境

时间:2018-11-12 15:25:23

标签: spring spring-batch

我想编写一个Spring Boot批处理应用程序,其中有一个充满事件的数据库表。我想做的是有一个多线程spring boot batch应用程序,它将以这种方式工作:

我想让5个线程运行,每个线程将保留一个偏移量以跟踪其已读取的事件,以便其他任何线程都不会再次读取同一事件。我想怎么做:

Thread 1 will pick up the event if eventId % 5 == 1
Thread 2 will pick up the event if eventId % 5 == 2
Thread 2 will pick up the event if eventId % 5 == 3
Thread 2 will pick up the event if eventId % 5 == 4
Thread 2 will pick up the event if eventId % 5 == 0

所以我希望能够在每个线程的数据库表中保持偏移量。有没有一种方法可以使Spring启动环境以这种方式工作?

1 个答案:

答案 0 :(得分:0)

您可以根据描述的内容对表进行分区(我想您将有5个分区),并使用配置有5个线程的TaskExecutorPartitionHandler的分区步骤。通过此设置,您将实现所需的功能。

希望这会有所帮助。