I have a servlet S which handles callbacks from a 3rd party site.
The callback invocations happen in a specific order. Thus, I need to queue them.
I propose to use an in-memory queue like
java.util.ConcurrentLinkedQueue
So the logic looks like this:
- Servlet S receives a callback & queues the received item into queue Q.
- By this time, the thread that hosted an instance of servlet S would have terminated.
- A consumer thread reads from Q and processes each one serially.
As I understand it, each instance of Servlet S is executed in its own Thread.
How do I create a single Consumer Thread for the whole webapp (war) that will service a Queue ? Basically I need singleton instances of:
- Threadpool
- ConcurrentLinkedQueue