davidzollo commented on code in PR #10609:
URL: https://github.com/apache/seatunnel/pull/10609#discussion_r2980651033


##########
seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/JdbcOutputFormat.java:
##########
@@ -72,6 +78,44 @@ public void open() throws IOException {
                     e);
         }
         jdbcStatementExecutor = 
createAndOpenStatementExecutor(statementExecutorFactory);
+        scheduledFuture = createAndStartScheduledFlush();
+    }
+
+    private ScheduledFuture<?> createAndStartScheduledFlush() {
+        long batchIntervalMs = jdbcConnectionConfig.getBatchIntervalMs();
+        if (batchIntervalMs <= 0 || jdbcConnectionConfig.getBatchSize() == 1) {
+            LOG.info(
+                    "Periodic flush disabled: batch_interval_ms={}, 
batch_size={}",
+                    batchIntervalMs,
+                    jdbcConnectionConfig.getBatchSize());
+            return null;
+        }
+
+        executor =
+                Executors.newScheduledThreadPool(
+                        1,
+                        runnable -> {
+                            Thread thread = new Thread(runnable);
+                            thread.setDaemon(true);
+                            thread.setName("jdbc-batch-flush-scheduler");
+                            return thread;
+                        });
+
+        return executor.scheduleWithFixedDelay(
+                () -> {
+                    synchronized (JdbcOutputFormat.this) {
+                        if (!closed) {
+                            try {
+                                flush();
+                            } catch (Exception e) {
+                                flushException = e;
+                            }

Review Comment:
   It is recommended to add `LOG.error` logs in the exception handling of 
scheduled flushes (instead of just setting `flushException`), which will 
facilitate troubleshooting issues with failed scheduled flushes in the 
production environment.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to