title: asynchronous http request handling with tomcat and spring
body: <p>It's my first SO question so be patient with me :)</p>
  
  <p>I'm trying to create a service that:</p>
  
  <ol>
  <li>Receives HTTP GET requests containing a URL to query</li>
  <li>For a single GET request the service extracts the URL</li>
  <li>Queries a local DB about the URL</li>
  <li>If a result was found in the DB it will return it to the client and if not it will need to query some external services (that may take relatively long time to respond)</li>
  <li>Return the result of the URL to the client</li>
  </ol>
  
  <p>I'm running this on a virtual machine and Tomcat7 with spring.
  I'll apologize in advance and mention that I'm pretty new to Tomcat</p>
  
  <p>Anyway, I'm expecting a lot of concurrent GET requests to this service (hundreds of thousands of simultaneous requests)
  What I'm basically trying to achieve is to make this service as scalable as possible (and if that's not possible then at least a service that can handle hundreds of thousands of simultaneous requests)</p>
  
  <p>I've been reading A LOT about asynchronous requests handling in services and especially in Tomcat but I have some things that are still unclear to me:</p>
  
  <ol>
  <li>From the official tomcat website it seems that Tomcat contains number of acceptor threads and number of working threads.
  If so, why should I use AsyncContext? Whats the benefit of releasing a Tomcat's working thread and occupying a different thread in my application to do the exact same actions? (there's still 1 active thread in the system)</li>
  <li>Somewhat similar to the first question but are there any benefits for creating the AsyncContext and using it with a different thread? (a thread from a thread pool created in my application)</li>
  <li>Regarding the same issue, I've seen <a href="http://spring.io/blog/2012/05/07/spring-mvc-3-2-preview-introducing-servlet-3-async-support">here</a> that I can also return a Callable or a DeferredResult and process it with either one of Tomcat's threads or with one of my own threads. Are there any benefits for returning a Callable or using a DeferredResult over just processing the AsyncContext from the requests?</li>
  <li>Also, If I decide to return a callable, from what thread pool does Tomcat gets the thread to process my callable? Are the threads being used here the same working threads from Tomcat that I previously mentioned? If so, what benefits do I get from releasing one Tomcat working thread and using a different one instead?</li>
  <li>I've seen from Oracle's documentation that I can pass AsyncContext a Runnable object that will be processed concurrently, From where do the threads used to execute this Runnable come from? Do I have any control over it? Also, any benefits to passing the AsyncContext a Runnable over just passing the AsyncContext to one my threads?</li>
  </ol>
  
  <p>I apologize for asking so many questions regarding the same things but me and my colleagues are arguing over these things for over a week without any concrete answer.</p>
  
  <p>I have 1 more general question: 
  What do you think is the best way to make the service I described scalable? (putting aside adding more machines at the moment), could you post any examples or references for the purposed solution?</p>
  
  <p>I'd post more links of links I've been looking at but my current reputation doesn't allow it. 
  I'll be grateful for any understandable references or for concrete examples and I'll obviously be happy to clarify on any relevant issue</p>
  
  <p>Cheers!</p>