简体   繁体   English

如何在Java / Spring下管理繁重的任务?

[英]How manage heavy task under Java/Spring?

I have a dashboard where users can do modification to their customers datas. 我有一个仪表板,用户可以在其中修改客户数据。 Some modifications needs heavy processing on all those customers. 一些修改需要对所有这些客户进行大量处理。 I don't want to block my user waiting that the task finished so how can I manage this in background? 我不想阻止我的用户等待任务完成,所以如何在后台管理?

I saw Spring Batch but I'm not sure it's the good answer. 我看到了Spring Batch,但我不确定这是不是很好的答案。 Is there anything else? 还有别的事吗?

Thanks in advance for your help. 在此先感谢您的帮助。

请参阅(google) @Async和/或Spring AMQP / JMS

It is not a Spring specific feature, but if you work under a commercial java application server (say websphere, weblogic), you will have some implementation of workmanagers. 它不是Spring特有的功能,但如果您在商业Java应用程序服务器(例如websphere,weblogic)下工作,您将拥有一些工作管理器的实现。

http://docs.oracle.com/javaee/1.4/api/javax/resource/spi/work/WorkManager.html http://docs.oracle.com/javaee/1.4/api/javax/resource/spi/work/WorkManager.html

These are container-managed threadpools used to send work into the background. 这些是容器管理的线程池,用于将工作发送到后台。 You will find tools in your admin console to configure and fine tune them. 您可以在管理控制台中找到用于配置和微调它们的工具。

You should have a separte process or application to process this kind of heavy task. 您应该有一个separte进程或应用程序来处理这种繁重的任务。 Your main application have to communicate with this heavy-task-processor via any method like JMS, JGroups, ConcurrentLinkedQueue, or whatever you want. 您的主应用程序必须通过任何方法(如JMS,JGroups,ConcurrentLinkedQueue或任何您想要的方法)与此重任务处理器进行通信。 You can process (deque) each task one at time or using a thread pool. 您可以一次处理(解除)每个任务或使用线程池。 When the task is finish you have to implement a way to inform the main application the task has finished (JMS, subscription, etc..) 任务完成后,您必须实现一种方法来通知主应用程序任务已完成(JMS,订阅等)。

You already have an accepted answer, but I wanted to throw in another option FYI. 你已经有了一个接受的答案,但是我还想投入另一个选项FYI。

  • If you want to run within the same JVM, @Async and a task executor will work. 如果要在同一JVM中运行,@ Async和任务执行程序将起作用。
  • If you have a big job that needs progress tracking, resumes, etc. and doesn't user need interaction, Spring Batch works. 如果你有一份需要进度跟踪,简历等的大工作而且用户不需要交互,那么Spring Batch可以工作。
  • If you have big jobs that you want to trigger remotely, or as part of a message driven architecture, Spring Batch Integration is a new effort to better combine Spring Integration and Spring Batch. 如果您想要远程触发大型作业,或者作为消息驱动架构的一部分, Spring Batch Integration是一项新的工作,可以更好地结合Spring Integration和Spring Batch。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM