[英]Spring Boot Thread management
I am barely new with Spring framework and i would like to ask opinion of the experts. 我对Spring框架并不陌生,我想征询专家的意见。
It is a spring boot application with a rest end point, which everytime is called it will put an action on a queue that will be consumed by a thread. 它是一个带有休息端点的Spring Boot应用程序,每次调用该端点时,它将在队列中放置一个操作,该操作将被线程消耗。
The way I am organizing my code is: 我组织代码的方式是:
Application class A runnable class. 应用程序类可运行的类。 A component class.
组件类。
The component class has the annotatiion @Component and it only contains an instance for the thread. 组件类具有注释@Component,并且仅包含线程的实例。
@Component
public class ComponenteExample {
@Autowired
Runnable runnableImpl;
Thread thread;
@PostConstruct
private void init(){
thread = new thread(runnableImpl);
thread.start();
}
What I would like to ask if there is a better/elegant way to manage this thread. 我想问一下是否有更好/优雅的方法来管理此线程。 By this I mean if it could be Spring container to manage it?
我的意思是说它可以由Spring容器来管理吗?
For asynchronous call you can use https://spring.io/guides/gs/async-method/ 对于异步调用,您可以使用https://spring.io/guides/gs/async-method/
However if you want to use queues you should look at https://spring.io/guides/gs/messaging-jms 但是,如果要使用队列,则应查看https://spring.io/guides/gs/messaging-jms
And for event-driven application there is https://spring.io/guides/gs/messaging-reactor/ 对于事件驱动的应用程序,有https://spring.io/guides/gs/messaging-reactor/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.