Skip to content

Commit 45db826

Browse files
committed
Executor service shutdown moved to finally block
1 parent 9fff185 commit 45db826

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

data-loader/core/src/main/java/com/scalar/db/dataloader/core/dataexport/ExportManager.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,21 @@ public ExportReport startExport(
105105
isFirstBatch,
106106
exportReport));
107107
}
108-
executorService.shutdown();
109-
if (executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS)) {
110-
logger.info("All tasks completed");
111-
} else {
112-
logger.error("Timeout occurred while waiting for tasks to complete");
113-
// TODO: handle this
114-
}
115108
processFooter(exportOptions, tableMetadata, bufferedWriter);
116-
} catch (InterruptedException
117-
| IOException
118-
| UnknownTransactionStatusException
119-
| CrudException e) {
109+
} catch (IOException | UnknownTransactionStatusException | CrudException e) {
120110
logger.error("Error during export: ", e);
121111
} finally {
112+
executorService.shutdown();
113+
try {
114+
if (executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS)) {
115+
logger.info("All tasks completed");
116+
} else {
117+
logger.error("Timeout occurred while waiting for tasks to complete");
118+
}
119+
} catch (InterruptedException e) {
120+
Thread.currentThread().interrupt();
121+
logger.error("Interrupted while waiting for executor termination", e);
122+
}
122123
bufferedWriter.flush();
123124
}
124125
} catch (ExportOptionsValidationException | IOException | ScalarDbDaoException e) {

0 commit comments

Comments
 (0)