In a Servlet environment I try to implement a Messenger class for the jobs of taking messages to its queue and sending them to online users. Messenger is a Singleton implementing Runnable. I can't find a proper way to .start() the inner thread for checking the queue and sending the message (in an another thread). Can you please comment on the design, possible caveats and a way to .start()
What I try is to use the Messenger class as:
And than the inner polling thread get messages from the queue and send them
take a look at the java.util.concurrent API. Instantiate a ConcurrentLinkedQueue or something like that, and "plug" it to a ThreadPool. Each message added to the queue will be automatically consumed by the pool.