I have completed the following Java Servlet construction: [I believe the main idea is that of consumer-producer]
A Java servlet that receives multiple http POST requests
It puts all requests into a Queue [ConcurrentLinkedQueue]
All requests in the Queue are processed by a single and independent thread (like an engine). This thread works independently of the servlets. There is a good reason for the separate thread, since I need data from several and different http requests to do the processing. The Queue waits until it has enough requests and then starts the processing.
Now I'm in the final step: Once e.g. http request No1 has been processed by the independent thread engine, I need to notify the specific servlet thread (e.g. No1) where it came from so that I can reply, i.e. send the response back to the corresponding client.
How do I solve this threading issue? How can the single thread engine notify the correct servlet thread each time? How should I code this?