mgao0 commented on a change in pull request #1000:
URL: https://github.com/apache/helix/pull/1000#discussion_r439088620



##########
File path: 
helix-core/src/main/java/org/apache/helix/manager/zk/CallbackHandler.java
##########
@@ -818,4 +883,38 @@ public String getContent() {
         + ", _listener=" + _listener + ", _changeType=" + _changeType + ", 
_manager=" + _manager
         + ", _zkClient=" + _zkClient + '}';
   }
+
+  /**
+   * Used to shut down a periodic triggered task
+   */
+  private void shutDownTriggerTask(boolean isShutdown) {
+    if (_scheduledTriggerFuture != null) {
+      _scheduledTriggerFuture.cancel(true);
+    }
+    if (_periodicTriggerExecutor != null && isShutdown) {
+      _periodicTriggerExecutor.shutdownNow();
+      _periodicTriggerExecutor = null;
+    }
+  }
+
+  /**
+   * Used to initialize a periodic triggered task
+   * Schedule tasks in a task executor with fixed intervals
+   */
+  private void initTriggerTask() {
+    if (_periodicTriggerInterval <= 0) {
+      return;
+    }
+    shutDownTriggerTask(false);
+    _lastInvokeTime = System.currentTimeMillis();
+    if (_periodicTriggerExecutor == null) {
+      _periodicTriggerExecutor = new ScheduledThreadPoolExecutor(1);
+      // When cancelling the task future, it removes the task from the queue
+      // so we won't have a memory leakage when we cancel scheduled task
+      _periodicTriggerExecutor.setRemoveOnCancelPolicy(true);
+    }
+    _scheduledTriggerFuture = _periodicTriggerExecutor
+        .scheduleWithFixedDelay(new TriggerTask(), _periodicTriggerInterval,

Review comment:
       Discussed offline. A single long running thread is sufficient. Updated.




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

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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to