rogerpt
rogerpt

Reputation: 59

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?

Upvotes: 0

Views: 21060

Answers (1)

bsmk
bsmk

Reputation: 1357

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/

Upvotes: 3

Related Questions