简体   繁体   English

我可以在Spring Boot应用程序中运行长任务吗?

[英]Can I run long tasks in a Spring Boot application?

I have a Spring Boot application, which shows some data from MongoDB on an AngularJS page and allows the user to change it. 我有一个Spring Boot应用程序,它在AngularJS页面上显示来自MongoDB的一些数据,并允许用户更改它。

Now I need to create a mechanism, which allows me to 现在我需要创建一个允许我的机制

  1. run a long (1-3 hours) Java method, 运行一个长(1-3小时)的Java方法,
  2. which produces some files and 它产生一些文件和
  3. observe its state via web (does it run, is it finished, did it crash?). 通过网络观察它的状态(它是否运行,是否完成,是否崩溃?)。

Can I implement this in scope of the Spring Boot application? 我可以在Spring Boot应用程序的范围内实现它吗? If yes, what parts of Spring can I use to do that? 如果是的话,我可以使用Spring的哪些部分来做到这一点?

I would argue that it's not good idea to embed batch processing into your service exposing MongoDB data store. 我认为将批处理嵌入到暴露MongoDB数据存储的服务中并不是一个好主意

I would create separate batch application . 我会创建单独的批处理应用程序 Spring Batch would be natural choice if you are using Spring stack. 如果您使用Spring堆栈, Spring Batch将是自然的选择 You would need to figure out how you want to host Spring Batch job and how you want to trigger and schedule it. 您需要弄清楚如何托管Spring Batch作业以及如何触发和计划它。 Spring Batch needs SQL storage for it's metadata . Spring Batch需要SQL存储才能获得元数据

Status of the batch processing could be monitored by one other application with Spring Batch Admin module running on Servlet container . 可以通过在Servlet容器上运行Spring Batch Admin模块的另一个应用程序监视批处理的状态。 If you point this application to SQL storage of Spring Batch job application, you get monitoring of status via web UI out of the box . 如果将此应用程序指向Spring Batch作业应用程序的SQL存储,则可以通过Web UI立即监视状态

Of course it could run each app with Spring Boot. 当然它可以使用Spring Boot运行每个应用程序。

If you don't want to handle this operational complexity it brings to host there three applications, yous still can all three embed into one and it would work fine with Spring Boot . 如果你不想处理这种操作复杂性,它会带来三个应用程序,你们仍然可以它们全部嵌入到一个应用程序中, 它可以在Spring Boot中正常工作 You could even execute jobs with parameters manually or restart them via Spring Batch Admin configured to have access to Spring Batch Job beans. 您甚至可以手动执行带参数的作业,也可以通过配置为可以访问Spring Batch Job bean的Spring Batch Admin重新启动它们。

You could also explore using MongoDb as storage for Spring Batch metadata. 您还可以使用MongoDb作为Spring Batch元数据的存储进行探索。 Eg this project may help . 例如,该项目可能有所帮助 But such mechanism would need to be used by Spring Batch application and also by Spring Batch Admin module visualizing status of processing. 但是这种机制需要由Spring Batch应用程序使用,也需要Spring Batch Admin模块可视化处理状态。

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

相关问题 我可以运行一个空的 spring 引导应用程序而不会出现错误吗? - Can I run an empty spring boot application without getting an Error? 如何在端口 80 上运行 Spring Boot 应用程序 - How can I run a Spring Boot application on port 80 我可以从另一个 spring boot 应用程序中编译并运行 spring boot jar 吗? - Can I compile and run a spring boot jar from inside another spring boot application? 应用程序启动后的Spring Boot长期运行方法 - Spring boot long run method after application starts 无法使用docker运行Spring Boot Application - Can't run Spring Boot Application with docker 无法运行Spring Boot测试应用程序 - Can't run Spring Boot test application 为什么我可以在 CLI 中运行我的应用程序 VSCode 但不能正确运行?它是一个 spring 启动应用程序 - Why can I run my app VSCode but not correctly in CLI?, its a spring boot application 我可以运行我的 Spring-boot 应用程序无法调试而不是运行抛出无效参数名称“” - I can run my Spring-boot application can't debug instead of run is throws Invalid parameter name “” 在 spring mvc 应用程序中运行 spring 启动应用程序 - run spring boot application in spring mvc application 在服务器上运行Spring Boot应用程序 - Run spring boot application on server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM