mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

ludovicp
31.03.2010 54b634bf8c813f53c3f532d467c9f66f32ff79b1
Changed from using a Timer to invoke the FirstPhaseProgressTask to a ScheduledThreadPoolExecutor. The main thread will now await shutdown of all the ExecutorServices before returning from phase one processing. This will ensure there are no race conditions when switch to phase two.
1 files modified
29 ■■■■■ changed files
opendj-sdk/opends/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java 29 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java
@@ -928,8 +928,10 @@
  {
    initializeIndexBuffers();
    FirstPhaseProgressTask progressTask = new FirstPhaseProgressTask();
    Timer timer = new Timer();
    timer.scheduleAtFixedRate(progressTask, TIMER_INTERVAL, TIMER_INTERVAL);
    ScheduledThreadPoolExecutor timerService =
      new ScheduledThreadPoolExecutor(1);
    timerService.scheduleAtFixedRate(progressTask, TIMER_INTERVAL,
      TIMER_INTERVAL, TimeUnit.MILLISECONDS);
    scratchFileWriterService = Executors.newFixedThreadPool(2 * indexCount);
    bufferSortService = Executors.newFixedThreadPool(threadCount);
    ExecutorService execService = Executors.newFixedThreadPool(threadCount);
@@ -978,15 +980,21 @@
        result.get();
      }
    }
    // Shutdown the executor services
    timerService.shutdown();
    timerService.awaitTermination(30, TimeUnit.SECONDS);
    execService.shutdown();
    execService.awaitTermination(30, TimeUnit.SECONDS);
    bufferSortService.shutdown();
    bufferSortService.awaitTermination(30, TimeUnit.SECONDS);
    scratchFileWriterService.shutdown();
    scratchFileWriterService.awaitTermination(30, TimeUnit.SECONDS);
    //Try to clear as much memory as possible.
    scratchFileWriterList.clear();
    scratchFileWriterFutures.clear();
    indexKeyQueMap.clear();
    execService.shutdown();
    freeBufferQueue.clear();
    bufferSortService.shutdown();
    scratchFileWriterService.shutdown();
    timer.cancel();
  }
@@ -996,10 +1004,13 @@
  {
    SecondPhaseProgressTask progress2Task =
            new SecondPhaseProgressTask(reader.getEntriesRead());
    Timer timer2 = new Timer();
    timer2.scheduleAtFixedRate(progress2Task, TIMER_INTERVAL, TIMER_INTERVAL);
    ScheduledThreadPoolExecutor timerService =
      new ScheduledThreadPoolExecutor(1);
    timerService.scheduleAtFixedRate(progress2Task, TIMER_INTERVAL,
      TIMER_INTERVAL, TimeUnit.MILLISECONDS);
    processIndexFiles();
    timer2.cancel();
    timerService.shutdown();
    timerService.awaitTermination(30, TimeUnit.SECONDS);
  }