title: Delaying a Spring WebClient call with ScheduledExecutorService does not wait for response
body: <p>Given a simple REST controller and service method (Spring Boot 2.5.x and Java 8) how can I achieve the following?</p>
  <ol>
  <li>A client posts some data to the REST controller.</li>
  <li>The controller calls the service method.</li>
  <li>The service method shall invoke a REST call to an external API using the <code>WebClient</code> <strong>after a fixed delay</strong> of e.g. 10 s.</li>
  </ol>
  <p>While 1. and 2. are trivial, I struggle with 3. My first implementation looks like this, using a <code>ScheduledExecutorService</code>. This actually delays the execution of <code>sendNotification()</code> but it seems as if the result of this REST call is ignored. If the external API returns an e.g. HTTP 4xx/5xx, I would expect a <code>WebClientResponseException</code> but this does not happen.</p>
  <p>Maybe this has something to do with the <code>ScheduledExecutorService</code> and some thread issue?</p>
  <p><strong>REST Controller class</strong></p>
  <pre class="lang-java prettyprint-override"><code>@RestController
  @RequiredArgsConstructor
  public class ServiceController {
  
      private final SampleService sampleService;
  
      @PostMapping(value = &quot;/api&quot;)
      public String create(@RequestBody SampleRequest sampleRequest) {
          return sampleService.create(sampleRequest);
      }
  }
  </code></pre>
  <p><strong>Service class</strong></p>
  <pre class="lang-java prettyprint-override"><code>@Service
  @RequiredArgsConstructor
  public class SampleService {
  
      private final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
  
      public String create(SampleRequest sampleRequest) {
          final String result = processSampleRequest(sampleRequest);
          executorService.schedule(() -&gt; sendNotification(), 10, TimeUnit.SECONDS);
          return result;
      }
  
      public void sendNotification() {
          final WebClient webClient = WebClient.builder()
                  .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
                  .build();
          webClient.post()
                  .uri(&quot;http://localhost:5555&quot;)
                  .body(BodyInserters.fromValue(&quot;some string&quot;))
                  .retrieve()
                  .toBodilessEntity()
                  .block();    
      }
  }
  </code></pre>