From 54b634bf8c813f53c3f532d467c9f66f32ff79b1 Mon Sep 17 00:00:00 2001
From: ludovicp <ludovicp@localhost>
Date: Mon, 31 May 2010 09:03:31 +0000
Subject: [PATCH] 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.
---
opendj-sdk/opends/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java | 29 ++++++++++++++++++++---------
1 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/opendj-sdk/opends/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java b/opendj-sdk/opends/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java
index b134982..d74266c 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java
+++ b/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);
}
--
Gitblit v1.10.0