首页 文章

Spring Boot线程管理

提问于
浏览
0

我对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 回答

相关问题