I have a Java service that is multi-threaded. This a publisher-subscriber application.
There is a message bus and there are several plugin components listening to the message bus. Each request from a plugin is handled by the message bus in a separate thread. It runs as a Windows service.
In the stop method, currently what I am doing is calling System.exit(0)
. In several other similar questions, some people have said it to be a bad practice, while some others claim that it is fine. Even Sonarqube complains about it.
So what it is the graceful way to stop all these threads? Should I call Thread.interrupt
on them?
These clients are continuously listening to the message bus and if any event messages are received they process it.