繁体   English   中英

Spring Boot线程管理

[英]Spring Boot Thread management

我对Spring框架并不陌生,我想征询专家的意见。

它是一个带有休息端点的Spring Boot应用程序,每次调用该端点时,它将在队列中放置一个操作,该操作将被线程消耗。

我组织代码的方式是:

应用程序类可运行的类。 组件类。

组件类具有注释@Component,并且仅包含线程的实例。

@Component
public class ComponenteExample {
    @Autowired
    Runnable runnableImpl;
    Thread thread;

    @PostConstruct
    private void init(){
       thread = new thread(runnableImpl);
       thread.start();
    }

我想问一下是否有更好/优雅的方法来管理此线程。 我的意思是说它可以由Spring容器来管理吗?

对于异步调用,您可以使用https://spring.io/guides/gs/async-method/

但是,如果要使用队列,则应查看https://spring.io/guides/gs/messaging-jms

对于事件驱动的应用程序,有https://spring.io/guides/gs/messaging-reactor/

暂无
暂无

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

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