在我的应用程序中,我有一组计划任务,用于处理所有用户的数据并执行各种任务,例如收入、税务计算、为所有用户生成报表。由于这些进程需要为每个用户运行,因此由于用户数量较多,它们需要花费大量时间(许多小时)。一个用户的数据处理完全独立于另一用户的数据处理,因此它们可以并行运行。我在这里有什么选择?进行此类大型/批量操作的最佳实践是什么? 我们使用带有 spring、jpa 和 hibernate 的 J2SE 平台。
最佳答案
您应该通过批处理执行相同的操作。
既然您提到您正在使用 Spring 进行操作,您可以考虑使用 Spring Batch 。
Spring Batch provides reusable functions that are essential in processing large volumes of records, including logging/tracing, transaction management, job processing statistics, job restart, skip, and resource management. It also provides more advanced technical services and features that will enable extremely high-volume and high performance batch jobs through optimization and partitioning techniques.
查看 Reference manual以及如何实现。
关于java - 通过计划任务进行批量操作的正确方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14036956/