Proper way of running many long lived tasks in Java
I have a Java application that listens to 15 incoming message queues services (Such as rabbitMQ, kafka, etc). Each queue is being listened on a separate Thread. This is, on startup, I have 15 lines of Executors.newSingleThreadExecutor(new QueueListener("SomeQueueToListenTo"));
This QueueListener
threads are while true loops, so they will live until the JVM exits.
My question is: Is there a better way (better being: clean code/performance wise) to initialize these long lived threads?
For example: Is there a difference between doing Executors.newSingleThreadExecutor
15 times and creating a single threadpool with 15 threads, and then submit each listener to this threadpool?
Thanks in advance.
from Recent Questions - Stack Overflow https://ift.tt/3Bovbe7
https://ift.tt/eA8V8J
Comments
Post a Comment