@@ -80,11 +80,11 @@ public ExportReport startExport(
8080 ExecutorService executorService =
8181 Executors .newFixedThreadPool (exportOptions .getMaxThreadCount ());
8282
83- BufferedWriter bufferedWriter = new BufferedWriter (writer );
8483 boolean isJson = exportOptions .getOutputFileFormat () == FileFormat .JSON ;
8584
8685 try (TransactionManagerCrudOperable .Scanner scanner =
87- createScanner (exportOptions , dao , manager )) {
86+ createScanner (exportOptions , dao , manager );
87+ BufferedWriter bufferedWriter = new BufferedWriter (writer )) {
8888
8989 Iterator <Result > iterator = scanner .iterator ();
9090 AtomicBoolean isFirstBatch = new AtomicBoolean (true );
@@ -103,32 +103,22 @@ public ExportReport startExport(
103103 isFirstBatch ,
104104 exportReport ));
105105 }
106- } catch (UnknownTransactionStatusException | CrudException e ) {
107- logger .error ("Error during export: " , e );
108- } finally {
109106 executorService .shutdown ();
110- try {
111- if (executorService .awaitTermination (Long .MAX_VALUE , TimeUnit .NANOSECONDS )) {
112- logger .info ("All tasks completed" );
113- // Process footer after all tasks are complete
114- try {
115- processFooter (exportOptions , tableMetadata , bufferedWriter );
116- } catch (IOException e ) {
117- logger .error ("Error processing footer" , e );
118- }
119- } else {
120- logger .error ("Timeout occurred while waiting for tasks to complete" );
121- }
122- } catch (InterruptedException e ) {
123- Thread .currentThread ().interrupt ();
124- logger .error ("Interrupted while waiting for executor termination" , e );
107+ if (executorService .awaitTermination (Long .MAX_VALUE , TimeUnit .NANOSECONDS )) {
108+ logger .info ("All tasks completed" );
109+ processFooter (exportOptions , tableMetadata , bufferedWriter );
110+ } else {
111+ logger .error ("Timeout occurred while waiting for tasks to complete" );
112+ // TODO: handle this
125113 }
126-
127- // Flush buffered writer
128- try {
129- bufferedWriter .flush ();
130- } catch (IOException e ) {
131- logger .error ("Error flushing writer" , e );
114+ } catch (InterruptedException
115+ | IOException
116+ | UnknownTransactionStatusException
117+ | CrudException e ) {
118+ logger .error ("Error during export: " , e );
119+ } finally {
120+ if (!executorService .isShutdown ()) {
121+ executorService .shutdownNow ();
132122 }
133123 }
134124 } catch (ExportOptionsValidationException | IOException | ScalarDbDaoException e ) {
0 commit comments