java Spring boot 异步数据处理
我有一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您确实需要/想要异步检查处理 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?