You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
We have code of configurable custom node where init() function creates scheduledFuture task to call some action after configured time (for example 24 hours).
As you can see code checks that if is previous scheduledFuture task is undone - if so, we cancel it and create another.
So if configuration changed in range to 24 hours after last configuration update - init() function executed repeatedly. This mean the previous task should be canceled, and previous scheduled task should not be called.
But it is not working. After each configuration update (within 24 hours) state of scheduledFuture still null and previous task will also be invoked, and not cancelled at all.
Any suggestions please how to fix it? How can we cancel scheduled task if configuration of node was updated before scheduled task is done?
Thanks
Here is code
`
private ScheduledExecutorService scheduledExecutor;
private ScheduledFuture<?> scheduledFuture;
private TbVixCalculateAvailabilityNodeConfiguration config;
@Override
public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
this.config = TbNodeUtils.convert(configuration, TbRaiseScheduledEventNodeConfiguration.class);
this.scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
if (scheduledFuture != null && !scheduledFuture.isDone()) {
// If there is a scheduled task running, cancel it
scheduledFuture.cancel(true);
}
scheduledFuture = scheduledExecutor.schedule(() -> doSomething(ctx), 86400, TimeUnit.MILLISECONDS);
}
`
Environment
OS: Ubuntu
ThingsBoard: V3.6.1
Language: Java
The text was updated successfully, but these errors were encountered:
New node instance is created after updating its configuration, and the old one is destroyed.
In order to cancel the previous scheduled task, you need to do that in the destroy method.
New node instance is created after updating its configuration, and the old one is destroyed. In order to cancel the previous scheduled task, you need to do that in the destroy method.
Component
Description
We have code of configurable custom node where init() function creates scheduledFuture task to call some action after configured time (for example 24 hours).
As you can see code checks that if is previous scheduledFuture task is undone - if so, we cancel it and create another.
So if configuration changed in range to 24 hours after last configuration update - init() function executed repeatedly. This mean the previous task should be canceled, and previous scheduled task should not be called.
But it is not working. After each configuration update (within 24 hours) state of scheduledFuture still null and previous task will also be invoked, and not cancelled at all.
Any suggestions please how to fix it? How can we cancel scheduled task if configuration of node was updated before scheduled task is done?
Thanks
Here is code
`
`
Environment
The text was updated successfully, but these errors were encountered: