[英]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.