diff --git a/spark/src/main/java/org/opensearch/sql/spark/cluster/ClusterManagerEventListener.java b/spark/src/main/java/org/opensearch/sql/spark/cluster/ClusterManagerEventListener.java index 8f38583b3f..f04c6cb830 100644 --- a/spark/src/main/java/org/opensearch/sql/spark/cluster/ClusterManagerEventListener.java +++ b/spark/src/main/java/org/opensearch/sql/spark/cluster/ClusterManagerEventListener.java @@ -133,7 +133,18 @@ public void beforeStop() { } }); } - initializeStreamingJobHouseKeeperCron(); + + if (flintStreamingJobHouseKeeperCron == null) { + initializeStreamingJobHouseKeeperCron(); + clusterService.addLifecycleListener( + new LifecycleListener() { + @Override + public void beforeStop() { + cancel(flintStreamingJobHouseKeeperCron); + flintStreamingJobHouseKeeperCron = null; + } + }); + } } private void initializeStreamingJobHouseKeeperCron() {