我对Spring框架几乎不熟悉,我想问一下专家的意见 .
它是一个带有休息结束点的spring boot应用程序,每次调用它都会对一个将由线程使用的队列执行操作 .
我组织代码的方式是:
应用程序类可运行的类 . 组件类 .
组件类具有注释@Component,它只包含线程的实例 .
@Component
public class ComponenteExample {
@Autowired
Runnable runnableImpl;
Thread thread;
@PostConstruct
private void init(){
thread = new thread(runnableImpl);
thread.start();
}
我想问一下,如果有一个更好/更优雅的方式来管理这个线程 . 我的意思是,如果它可以是Spring容器来管理它?
1 回答
对于异步调用,您可以使用https://spring.io/guides/gs/async-method/
但是如果你想使用队列,你应该看https://spring.io/guides/gs/messaging-jms
对于事件驱动的应用程序,有https://spring.io/guides/gs/messaging-reactor/