title: How to work correctly with ThreadPoolExecutor in Spring Boot Application
body: <p>I have a <code>Spring Boot Application</code>. </p>
  
  <p>My application sends requests to another applications using <code>restTemplate</code>.</p>
  
  <p>I need to send a request to one hundred different applications(on different servers). I use:</p>
  
  <pre><code>publi class Service {
      private RestClient restClient;
      private List&lt;String&gt; urls;
      private ThreadPoolExecutor executor;
  
      public Service(RestClient restClient, List&lt;String&gt; urls, ThreadPoolExecutor executor){
         this.restClient = restClient;
         this.urls = urls;
         this.executor = executor;
      }
  
      public void sendPost(Entity entity){
           for (String url: urls){
               executor.execute(() -&gt; restClient.create(url, entity);
           }
      }
  
  }
  </code></pre>
  
  <p>I am trying to use <code>ThreadPoolExecutor(fixedSizeThreadPool)</code> but I have some questions. </p>
  
  <p><strong>1</strong>.I read up that <code>threadPoolExecutor</code> is thread-safe. Does It means that I can invoke <code>execute()</code> at the same time from different threads and It will work properly?<br>
  <strong>2</strong>. If there are no idle threads in <code>threadPoolExecutor</code> It will slow down the application and I should to choose rational pool size, right?<br>
  <strong>3</strong>. For example, I need to write executed urls in <code>ArrayList</code>: </p>
  
  <pre><code>public void sendPost(Entity entity){
           List&lt;String&gt; executedUrls = new ArrayList&lt;&gt;();  
           for (String url: urls){
               executor.execute(() -&gt; restClient.create(url, entity, executedUrls);
           }
  }
  </code></pre>
  
  <p><code>RestClient</code> sends a request and if It is successfully executed It will be added in <code>ArrayList</code>.  </p>
  
  <p>I expect that <code>ArrayList</code> will have list of successfully executed urls If I have an exception in any thread from <code>threadPool</code>.<br>
   Will It work as I expect or I can have something like <em>lost update</em>? </p>