I am writing a web service in Java which needs to handle a large number of requests / second. The general flow will be:
- Web service receives a request from client
- Returns a 'keep polling me' response to client
- Calls another web service (or services), and waits for them to respond (with a timeout)
- Client polls our web service, until it receives a response (with a timeout)
Researching on the Internet, I have found two general approaches to writing web services:
- Spawn a thread for each request
- Use the Reactor pattern (central dispatcher thread responds to IO events)
Do you have a recommendation for which approach is generally better, and what are the pros/cons of each approach? I would also appreciate pointers to examples.