java Spring boot 异步数据处理

发布于 2025-01-15 23:03:53 字数 191 浏览 2 评论 0原文

我有一个 java spring boot 应用程序,带有一个处理 HTTP post 请求和嵌入式 tomcat 服务器的 REST 控制器。控制器始终获取事件并将它们存储在数据库中。我想在同一个应用程序中实现一个进程,异步检查某个事件是否已被存储。

请问我该如何实施?我可以用java线程做吗?我正在寻找实现此目的的最佳方法。

先感谢您

I have a java spring boot application with a REST-controller that processes HTTP post request and embedded tomcat server. the controller gets events all the time and stores them in a database. I want to implement a process in the same application that checks asynchronously if a certain event has been stored.

how can I implement this please? can I do with a java thread? I am looking for a optimal Way to implement this.

Thank you in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魄砕の薆 2025-01-22 23:03:53

如果您确实需要/想要异步检查处理 Web 请求时注册的某些事件,您可以使用 Spring @Scheduled 注解。您可以看一下: https://spring.io/guides/gs/scheduling- jobs/

Spring boot 对任务执行器(相当于线程池)进行了抽象,以便执行@Scheduled 任务。您可以在此处找到有关如何为 @Scheduled 注释配置任务执行器的有价值的信息:spring-boot 中默认的调度程序池大小是多少?

If you really need/want to check asynchronously for some events registered when processing a web request, you can use Spring @Scheduled annotation. You may take a look at: https://spring.io/guides/gs/scheduling-tasks/

Spring boot has the abstraction of task executor (equivalent to a thread pool) in order to execute @Scheduled tasks. You can find valuable information on how to configure the task executor for the @Scheduled annotation here: What is the default scheduler pool size in spring-boot?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文