title: Spring Boot Callable - 401 Unauthorized: [no body]
body: <p>I am using Callable interface inside a Spring Boot Application that sends auth request:</p>
  <pre><code>public class TestCallable implements Callable&lt;TestDto&gt; {
  
      TestEntity testEntity;
  
      public TestCallable(TestEntity testEntity) {
          this.testEntity = testEntity;
      }
  
  
      @Override
      public TestDto call() throws Exception {
          String authRequestBody = &quot;{&quot; +
                                      &quot;\&quot;username\&quot;: \&quot;&quot; + testEntity.getLogin() + &quot;\&quot;,&quot; +
                                      &quot;\&quot;password\&quot;: \&quot;&quot; + testEntity.getPassword() + &quot;\&quot;,&quot; +
                                      &quot;\&quot;client_id\&quot;: \&quot;&quot; + testEntity.getClientId() + &quot;\&quot;,&quot; +
                                      &quot;\&quot;client_secret\&quot;: \&quot;&quot; + testEntity.getClientSecret() + &quot;\&quot;&quot; +
                                   &quot;}&quot;;
          HttpHeaders authHeaders = new HttpHeaders();
          authHeaders.setContentType(MediaType.APPLICATION_JSON);
          authHeaders.set(&quot;Accept&quot;, &quot;application/json&quot;);
          authHeaders.set(&quot;Grant_type&quot;, &quot;password&quot;);
          HttpEntity&lt;String&gt; authEntity = new HttpEntity&lt;String&gt;(authRequestBody, authHeaders);
          RestTemplate restTemplate = new RestTemplate();
          TestDto testDto = testDto  = restTemplate.postForObject(testEntity.getEndpoint(), authEntity, TestDto.class);
  
          return testDto;
      }
  }
  </code></pre>
  <p>And I'm sending these requests in 4 threads:</p>
  <pre><code>List&lt;Future&lt;TestDto&gt;&gt;  futuresList = new ArrayList&lt;Future&lt;TestDto&gt;&gt;();
  ExecutorService pool = Executors.newFixedThreadPool(4);
  for (Integer i=0; i&lt;4; i++) {
      Callable&lt;TestDto&gt; callable = new TestCallable(testEntity);
      Future&lt;TestDto&gt; future = pool.submit(callable);
      futuresList.add(future);
  }
  </code></pre>
  <p>The issue is that sometimes I get the error &quot;401 Unauthorized: [no body]&quot;. For instance, I can receive 4 tokens from 4 callable jobs 5 times and get the error on the 6th attempt.</p>
  <p>If I change the number of threads to 2, then I have the error less often. 10 threads fail every time.</p>
  <p>And it always works fine in Postman.</p>
  <p>How can I understand the cause of the issue?</p>