title: Local vs Live - Multithreading using SimpleAsyncTaskExecutor
body: <p>I have a Java-Configuration with this annotaions:</p>
  
  <pre><code>@EnableAsync
  @EnableCaching
  @Configuration
  @EnableScheduling
  @ComponentScan("XXX")
  public class AppConfig implements AsyncConfigurer {
        ...
    @Override
    public Executor getAsyncExecutor() {
      SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor("Rm-");
      executor.setConcurrencyLimit(50);
      executor.setThreadPriority(Thread.MAX_PRIORITY);
      return executor;
    }
  }
  </code></pre>
  
  <p>Then I have 3 Schedulers </p>
  
  <pre><code>/**
   * Schedul on application start.
   */
  @Transactional
  @Scheduled(fixedDelay = Long.MAX_VALUE, initialDelay = 200)
  public void initialReplicate() {
      replicateFromTime(0l);
  }
  
  
  /**
   * Every minute check for synchronization.
   */
  @Transactional
  @Scheduled(cron = "0 * * * * * ")
  public void replicate() {
      long minutesSinceTimeRecord = System.currentTimeMillis() / 1000 / 60;
      replicateFromTime(minutesSinceTimeRecord);
  }
  
  @Transactional
  @Scheduled(fixedDelay = 1000)
  public void build() {
     LOG.info("Check if somethings to build.");
  }
  </code></pre>
  
  <p>What the replicate-from-time does: </p>
  
  <p>It calculates if the day is over, if so, it replicate once per day (and once at appstart) the schema of a database.
  For every table in the database one connection is created.</p>
  
  <pre><code>@Async
  @Transactional
  public Future&lt;Void&gt; readTable(TableModel table, String jdbcurl, Driver driver, Properties props, String schema,
          Set&lt;Throwable&gt; errors, String catalogName) {
      Connection connect = connectionService.connect(jdbcurl, errors, driver, props);
  
      final DatabaseMetaData metadata;
      try {
          metadata = connect.getMetaData();
      } catch (SQLException e) {
          errors.add(e);
          try {
              connect.close();
          } catch (SQLException e2) {
              errors.add(e2);
          }
          return new AsyncResult&lt;Void&gt;(null);
      }
      ...
  </code></pre>
  
  <p>There are 804 tables of any kind in the database (views, tables, temporary-tables, ...). For every table one connection is created. Makes 804 threads.</p>
  
  <p>The database is on the machin as the app. I test from localhost.</p>
  
  <h2>Problem:</h2>
  
  <p>On the remote-server, on appstart it replicates successfully. But no other scheduler are executed anymore except the <code>public void build()</code>-Scheduler. But only 48 times (see the limit of 50 threads in the configuration).</p>
  
  <p>From local-server, on appstart it replicates successfully. All 3 schedulers are working as expected.</p>
  
  <p>The tomcat on the server should run all schedulers, but it runs only one. The tomcat on my local machine run all schedulers.</p>
  
  <h2>Confusion</h2>
  
  <p>I expected to have more problems in a local environment, connected to a remote server than inside the remote-server itself.</p>
  
  <h2>Question</h2>
  
  <p>Any idea why the remote server have problems but my local machine not?</p>
  
  <h2>Technical details</h2>
  
  <ul>
  <li>Local is a <code>apache-tomcat-8.5.27</code>.</li>
  <li>Remote is a <code>apache-tomcat-8.5.15</code>.</li>
  <li>Database to replicate schema is a postgres.</li>
  </ul>