title: Spring Boot + multi threading + handling connection pool
body: <p>I am having a <code>Spring-boot</code> application which contains following:<br>
  1. REST-API<br>
  2. One thread running from start will execute one service <code>BS</code> (background service we can say)  </p>
  
  <p><b>Note</b>: <code>BS</code> have code to create <b>10</b> child thread which runs asynchronously to get things done.  </p>
  
  <p><b>Requirement</b>:<br>
  1. <code>BS</code> is independent thread which will run throughout the application with main thread.<br>
  2. <code>Child thread</code> : will be created in <code>BS</code> and will get collapsed in <code>BS</code> once things done.  </p>
  
  <p><b>Problem</b>: My thread <code>BS</code> needs to sleep(or you can say in <code>wait</code> state) if no work is pending and get back(<code>notify</code>) as and when work come. For this, I have used traditional way <code>wait...notify</code> but while waiting <code>BS</code> thread, the <b>10</b> child threads are executing the same code which <code>BS</code> thread is executing. I think thread pool management is not handled properly.<br>
  Help appreciate</p>
  
  <p><code>BS Thread</code> : <b> ThreadPoolTaskExecutor </b> &amp; <b> CommandLineRunner </b> with connection pool set to 1  </p>
  
  <pre><code> ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();  
      executor.setCorePoolSize(1);  
      executor.setMaxPoolSize(1);  
      executor.setQueueCapacity(500);  
      executor.setThreadNamePrefix("BS Thread:");  
      executor.initialize();  
      return executor;   
  </code></pre>
  
  <p><code>Child Thread</code> :   <b>10</b> threads created using following code:        </p>
  
  <pre><code> ExecutorService service = Executors.newFixedThreadPool(10);
   for (BSChildExecutor jobs : listOfJobs) {
       service.submit(jobs);
   }  
   service.shutdown();`    
  </code></pre>