| Author |
Singleton with a single worker thread
|
Ziphyre Marco
Greenhorn
Joined: Dec 18, 2008
Posts: 3
|
|
Hello,
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:
Messenger.getInstance().addMessageToQueue(...);
And than the inner polling thread get messages from the queue and send them
Thanks
|
 |
Evan Caballero
Ranch Hand
Joined: Dec 10, 2009
Posts: 59
|
|
|
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.
|
 |
 |
|
|
subject: Singleton with a single worker thread
|
|
|