我想写一个spring boot批处理应用程序,其中我有一个充满事件的数据库表。我想做的是有一个多线程的spring boot批处理应用程序,它将以这种方式工作:
我希望有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引导环境以这种方式工作?
发布于 2018-11-13 00:10:23
您可以根据您所描述的对表进行分区(我猜您将有5个分区),并使用配置有5个线程的TaskExecutorPartitionHandler的分区步骤。通过此设置,您将实现所需的功能。
希望这能有所帮助。
https://stackoverflow.com/questions/53265240
复制相似问题