简体   繁体   中英

Spring Boot Thread management

I am barely new with Spring framework and i would like to ask opinion of the experts.

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.

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
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?

For asynchronous call you can use 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

And for event-driven application there is https://spring.io/guides/gs/messaging-reactor/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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