title: How to start a new Thread in spring boot app from the same class
body: <p>everyone. I have a service class in my spring boot application. Where I should call one method sync and one async.</p>
  <pre><code>@Service
  public class CreationRequestServiceImpl implements CreationRequestService {
  
      @Autowired
      private MessageSender messageSender;
  
      @Override
      public void sendMessage() {
  
          sendMessageToManager(createParamMap(/*some param*/));
  
          //send message to customr async
          new Thread(
              () -&gt; sendMessageToCustomer(createParamMap(/*some param*/))
          ).start();
      }
  
      private void sendMessageToManager(Map&lt;String, String&gt; param) {
          MessageTemplate messageTemplate;
          //some code
          messageSender.send(messageTemplate)
      }
  
      private void sendMessageToCustomer(Map&lt;String, String&gt; param) {
          MessageTemplate messageTemplate;
          //some code
          messageSender.send(messageTemplate)
      }
  
      private Map&lt;String, String&gt; createParamMap(/*some param*/) {
          Map&lt;String, String&gt; param;
          //some code
          return param;
      }
  }
  </code></pre>
  <p>I use <em>new Thread(...).start()</em> to invoke method async.
  But I think it is not a good idea.</p>
  <p>I did the following changes:</p>
  <p>I define Executor bean in Configuration, add @EnableAsync</p>
  <pre><code>    @Bean(name = &quot;taskExecutor&quot;)
      public Executor getAsyncExecutor() {
          //some code
      }
  </code></pre>
  <p>create a new service for async invocation</p>
  <pre><code>@Service
  public class AsyncMessageSenderImpl implements AsyncMessageSender {
  
      @Async(&quot;taskExecutor&quot;)
      @Override
      public void run(Runnable runnable) {
          runnable.run();
      }
  }
  </code></pre>
  <p>Refactor my CreationRequestServiceImpl class</p>
  <pre><code>@Service
  public class CreationRequestServiceImpl implements CreationRequestService {
  
      @Autowired
      private MessageSender messageSender;
  
      @Autowired
      private AsyncMessageSender asyncMessageSender;
  
      @Override
      public void sendMessage() {
  
          sendMessageToManager(createParamMap(/*some param*/));
  
          //send message to customr async
          asyncMessageSender.run(
              () -&gt; sendMessageToCustomer(createParamMap(/*some param*/))
          );
      }
  
      private void sendMessageToManager(Map&lt;String, String&gt; param) {
          MessageTemplate messageTemplate;
          //some code
          messageSender.send(messageTemplate)
      }
  
      private void sendMessageToCustomer(Map&lt;String, String&gt; param) {
          MessageTemplate messageTemplate;
          //some code
          messageSender.send(messageTemplate)
      }
  
      private Map&lt;String, String&gt; createParamMap(/*some param*/) {
          Map&lt;String, String&gt; param;
          //some code
          return param;
      }
  }
  
  </code></pre>
  <p>But this is not working async.</p>
  <p><strong>QUESTION:</strong></p>
  <ol>
  <li>How can I replace Thread(...).start() to start my method async. OR</li>
  <li>How can I make the second example to work?</li>
  </ol>