title: Is this possible to apply bucketisation in Spring Boot (TOMCAT)
body: <p>I exposed 2 api's <br></p>
  <p><em><strong>/endpoint/A</strong></em>  and <em><strong>/endpoint/B</strong></em>  .<br></p>
  <pre><code>@GetMapping(&quot;/endpoint/A&quot;)
      public ResponseEntity&lt;ResponseA&gt; controllerA() throws InterruptedException {
  
          ResponseA responseA = serviceA.responseClient();
          return ResponseEntity.ok().body(responseA);
      }
  
  
  
  @GetMapping(&quot;/endpoint/B&quot;)
      public ResponseEntity&lt;ResponseA&gt; controllerB() throws InterruptedException {
  
          ResponseA responseB = serviceB.responseClient();
          return ResponseEntity.ok().body(responseB);
      }
  </code></pre>
  <p>Services implemented regarding endpoint A internally call <em><strong>/endpoint/C</strong></em>   and endpoint B internally call <em><strong>/endpoint/D</strong></em>. <br></p>
  <p>As external service <em><strong>/endpoint/D</strong></em> taking more time i.e getting response from <em><strong>/endpoint/A</strong></em> takes more time hence whole threads are stucked that is affecting  <em><strong>/endpoint/B</strong></em>.<br>
  I tried to solve this using executor service having following implementation <br></p>
  <pre><code>@Bean(name = &quot;serviceAExecutor&quot;)
      public ThreadPoolTaskExecutor serviceAExecutor(){
  
          ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
          taskExecutor.setCorePoolSize(100);
          taskExecutor.setMaxPoolSize(120);
          taskExecutor.setQueueCapacity(50);
          taskExecutor.setKeepAliveSeconds(120);
          taskExecutor.setThreadNamePrefix(&quot;serviceAExecutor&quot;);
          return taskExecutor;
      }
  </code></pre>
  <p>Even after implementing this if I received more than 200 request on <em><strong>/endpoint/A</strong></em> simultaneously (greater than default max number of threads in Tomcat server) then I am not getting responses from <em><strong>/endpoint/B</strong></em> as all threads are busy for getting response from endpoint A or in queue.<br></p>
  <p>Can someone plz suggest  is there any way to apply bucketization on each exposed endpoint level and allow only limited request to process at a time &amp; put remaining into bucket/queue so that request on other endpoints can work properly ?</p>
  <p>Edit:-  following is solution approach</p>
  <pre><code>@GetMapping(&quot;/endpoint/A&quot;)
          public CompletableFuture&lt;ResponseEntity&lt;ResponseA&gt;&gt; controllerA() throws InterruptedException {
      
              return CompletableFuture.supplyAsync(()-&gt;controllerHelperA());
          }
  
  
  
      @GetMapping(&quot;/endpoint/B&quot;)
          public CompletableFuture&lt;ResponseEntity&lt;ResponseB&gt;&gt; controllerB() throws InterruptedException {
      
              return CompletableFuture.supplyAsync(()-&gt;controllerHelperB());
          }
  
  private ResponseEntity&lt;ResponseA&gt; controllerHelperA(){
  
          ResponseA responseA = serviceA.responseClient();
          return ResponseEntity.ok().body(responseA);
      }
  
  private ResponseEntity&lt;ResponseB&gt; controllerHelperB(){
  
          ResponseB responseB = serviceB.responseClient();
          return ResponseEntity.ok().body(responseB);
      }
  </code></pre>