jt2594838 commented on code in PR #15599:
URL: https://github.com/apache/iotdb/pull/15599#discussion_r2122465409


##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/agent/runtime/PipePeriodicalJobExecutor.java:
##########
@@ -21,15 +21,47 @@
 
 import org.apache.iotdb.commons.concurrent.IoTDBThreadPoolFactory;
 import org.apache.iotdb.commons.concurrent.ThreadName;
+import org.apache.iotdb.commons.concurrent.threadpool.ScheduledExecutorUtil;
 import org.apache.iotdb.commons.pipe.config.PipeConfig;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
 /**
  * The shortest scheduling cycle for these jobs is {@link
  * PipeConfig#getPipeSubtaskExecutorCronHeartbeatEventIntervalSeconds()}, 
suitable for jobs that are
  * NOT time-critical.
  */
 public class PipePeriodicalJobExecutor extends 
AbstractPipePeriodicalJobExecutor {
 
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(PipePeriodicalJobExecutor.class);
+  // This background service is used to execute jobs that need to be cancelled 
and released.
+  private static final ScheduledExecutorService backgroundService =
+      IoTDBThreadPoolFactory.newSingleThreadScheduledExecutor(
+          ThreadName.PIPE_PROGRESS_INDEX_BACKGROUND_SERVICE.getName());
+
+  public static Future<?> submitBackgroundJob(
+      Runnable job, long initialDelayInMs, long periodInMs) {
+    return ScheduledExecutorUtil.safelyScheduleWithFixedDelay(
+        backgroundService, job, initialDelayInMs, periodInMs, 
TimeUnit.MILLISECONDS);
+  }
+
+  public static void shutdownBackgroundService() {
+    backgroundService.shutdownNow();
+    try {
+      if (!backgroundService.awaitTermination(30, TimeUnit.SECONDS)) {
+        LOGGER.warn("Pipe progressIndex background service did not terminate 
within {}s", 30);
+      }
+    } catch (InterruptedException e) {
+      LOGGER.warn("Pipe progressIndex background service still doesn't exit 
after 30s");

Review Comment:
   This message (line 60) is imprecise.



-- 
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