diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/scheduling/StandardProcessScheduler.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/scheduling/StandardProcessScheduler.java index 1627994de0..4407451a8a 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/scheduling/StandardProcessScheduler.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/scheduling/StandardProcessScheduler.java @@ -43,7 +43,6 @@ import org.apache.nifi.controller.ProcessorNode; import org.apache.nifi.controller.ReportingTaskNode; import org.apache.nifi.controller.ScheduledState; import org.apache.nifi.controller.annotation.OnConfigured; -import org.apache.nifi.controller.service.ControllerServiceNode; import org.apache.nifi.controller.service.ControllerServiceProvider; import org.apache.nifi.encrypt.StringEncryptor; import org.apache.nifi.engine.FlowEngine; @@ -374,9 +373,9 @@ public final class StandardProcessScheduler implements ProcessScheduler { return; } + state.setScheduled(false); getSchedulingAgent(procNode).unschedule(procNode, state); procNode.setScheduledState(ScheduledState.STOPPED); - state.setScheduled(false); } final Runnable stopProcRunnable = new Runnable() { @@ -474,8 +473,8 @@ public final class StandardProcessScheduler implements ProcessScheduler { if (!state.isScheduled()) { return; } + state.setScheduled(false); - getSchedulingAgent(connectable).unschedule(connectable, state); if (!state.isScheduled() && state.getActiveThreadCount() == 0 && state.mustCallOnStoppedMethods()) { diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/scheduling/TimerDrivenSchedulingAgent.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/scheduling/TimerDrivenSchedulingAgent.java index a620202d25..17fb9f88b5 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/scheduling/TimerDrivenSchedulingAgent.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/scheduling/TimerDrivenSchedulingAgent.java @@ -130,11 +130,12 @@ public class TimerDrivenSchedulingAgent implements SchedulingAgent { // so that we can do this again the next time that the component is yielded. if (scheduledFuture.cancel(false)) { final long yieldNanos = TimeUnit.MILLISECONDS.toNanos(yieldMillis); - final ScheduledFuture newFuture = flowEngine.scheduleWithFixedDelay(this, yieldNanos, - connectable.getSchedulingPeriod(TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS); synchronized (scheduleState) { if ( scheduleState.isScheduled() ) { + final ScheduledFuture newFuture = flowEngine.scheduleWithFixedDelay(this, yieldNanos, + connectable.getSchedulingPeriod(TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS); + scheduleState.replaceFuture(scheduledFuture, newFuture); futureRef.set(newFuture); } @@ -152,11 +153,11 @@ public class TimerDrivenSchedulingAgent implements SchedulingAgent { // an accurate accounting of which futures are outstanding; we must then also update the futureRef // so that we can do this again the next time that the component is yielded. if (scheduledFuture.cancel(false)) { - final ScheduledFuture newFuture = flowEngine.scheduleWithFixedDelay(this, NO_WORK_YIELD_NANOS, - connectable.getSchedulingPeriod(TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS); - synchronized (scheduleState) { if ( scheduleState.isScheduled() ) { + final ScheduledFuture newFuture = flowEngine.scheduleWithFixedDelay(this, NO_WORK_YIELD_NANOS, + connectable.getSchedulingPeriod(TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS); + scheduleState.replaceFuture(scheduledFuture, newFuture); futureRef.set(newFuture); }