title: similar concurrent tasks, very different running time (Java)
body: <p>I have an job to insert 8 millions rows into an oracle database table. I scaled out the job onto the 8 cores of the CPU, here is the sample code:</p>
  
  <pre><code>final long start = System.currentTimeMillis();
  final int batchSize = 800000;
  final int nCore = Runtime.getRuntime().availableProcessors();
  final int batchPerCore = batchSize / nCore;
  final CountDownLatch taskCountDown = new CountDownLatch(nCore);
  final CountDownLatch kickoffLatch = new CountDownLatch(1);
  final ExecutorService es = Executors.newFixedThreadPool(nCore);
  
  Class.forName("oracle.jdbc.driver.OracleDriver");
  
  for (int n = 0; n &lt; nCore; n++) {
  
      es.submit(() -&gt; {
  
          log.info("Thread {} starts working on {} insertion jobs.", Thread.currentThread().getName(), batchPerCore);
          try (Connection conn = DriverManager.getConnection(DB_URL, USER_NAME, PASSWORD)) {
  
              Assert.assertNotNull("connection established", conn);
              conn.setAutoCommit(false);
              PreparedStatement pstmt = conn.prepareStatement(PREP_STATEMENT);
  
  
              for (int i = 0; i &lt; batchPerCore; i++) {
                  initPrepTranStatement(pstmt);
                  pstmt.addBatch();
  
              }
  
              int[] resultTran = pstmt.executeBatch();
              Assert.assertEquals(resultTran.length, batchPerCore);
              conn.commit();
              log.info("Thread {} completed its job!", Thread.currentThread().getName());
              taskCountDown.countDown();
  
          } catch (SQLException e) {
              e.printStackTrace();
          }
  
      });
  
  } // ~ for ~
  
  es.shutdown();
  
  kickoffLatch.countDown();
  
  taskCountDown.await();
  
  log.info("It takes {} milliseconds to complete all {} tasks for {} insertions each. ",
          (System.currentTimeMillis()-start), nCore, batchPerCore);
  </code></pre>
  
  <p>as it proceeded, it shows 3 tasks completed running the courses at 2:09 PM, but others still pending as of this writing (3:29PM).</p>
  
  <p>Here is the log:</p>
  
  <pre><code>Apr 27, 2020 1:25:17 PM com.db.loader.DBFlexDataLoadingPerfTest lambda$4
  INFO: Thread pool-1-thread-7 starts working on 100000 insertion jobs.
  Apr 27, 2020 1:25:17 PM com.db.loader.DBFlexDataLoadingPerfTest lambda$4
  INFO: Thread pool-1-thread-2 starts working on 100000 insertion jobs.
  Apr 27, 2020 1:25:17 PM com.db.loader.DBFlexDataLoadingPerfTest lambda$4
  INFO: Thread pool-1-thread-5 starts working on 100000 insertion jobs.
  Apr 27, 2020 1:25:17 PM com.db.loader.DBFlexDataLoadingPerfTest lambda$4
  INFO: Thread pool-1-thread-8 starts working on 100000 insertion jobs.
  Apr 27, 2020 1:25:17 PM com.db.loader.DBFlexDataLoadingPerfTest lambda$4
  INFO: Thread pool-1-thread-4 starts working on 100000 insertion jobs.
  Apr 27, 2020 1:25:17 PM com.db.loader.DBFlexDataLoadingPerfTest lambda$4
  INFO: Thread pool-1-thread-3 starts working on 100000 insertion jobs.
  Apr 27, 2020 1:25:17 PM com.db.loader.DBFlexDataLoadingPerfTest lambda$4
  INFO: Thread pool-1-thread-6 starts working on 100000 insertion jobs.
  Apr 27, 2020 1:25:17 PM com.db.loader.DBFlexDataLoadingPerfTest lambda$4
  INFO: Thread pool-1-thread-1 starts working on 100000 insertion jobs.
  Apr 27, 2020 2:09:53 PM com.db.loader.DBFlexDataLoadingPerfTest lambda$4
  INFO: Thread pool-1-thread-4 completed its job!
  Apr 27, 2020 2:09:53 PM com.db.loader.DBFlexDataLoadingPerfTest lambda$4
  INFO: Thread pool-1-thread-6 completed its job!
  Apr 27, 2020 2:09:53 PM com.db.loader.DBFlexDataLoadingPerfTest lambda$4
  INFO: Thread pool-1-thread-7 completed its job!
  </code></pre>
  
  <p>Using DriverManager in this case is not a good idea, I should have used a DataSource implementation, nevertheless it is not relevant or affecting the purpose of this test. </p>
  
  <p>Given that all tasks are the same in terms of the nature of the job and running fashion, I can't get it why some are seriously behind others, and more likely they are just hanging there.</p>
  
  <p>No particular JVM arguments were set. The machine is Windows 10 pro, with a 8-core i7-6700 and 32G RAM.</p>