title: Thread Spawning in Java
body: <p>I am developing a service which figures out the freights and frequencies to deliver a product to the customer.</p>
  
  <p>The flow goes as below-</p>
  
  <ol>
  <li>I receive a request for a one item</li>
  <li>For every item I have 5 different Time Windows to check</li>
  <li>For every Time Window, I have 21 different days to check for weekly frequencies. </li>
  </ol>
  
  <p>If I try to achieve this without spawning threads my service takes around 1 second to compute all the desired functionality. </p>
  
  <p>To reduce the response time, I have built the service by spawning threads at different levels as below -</p>
  
  <ol>
  <li>Spawned threads for every item in the request</li>
  <li>Spawned threads per item per window (5 windows would correspond to 5 threads)</li>
  <li>Spawned threads per date per window (21 dates would correspond to 21 threads)</li>
  </ol>
  
  <p>So if I get a single item in the request, I would spawn in total of (1x5x21= 105 threads). Does this look correct? Should I worry running out of heap space or Context Switching Time?</p>
  
  <p>Any leads would be helpful. Thanks in advance!!</p>