Good day.
I managed to find the cause of this error.
Error description: When updating plugin from Felix console, all schedulers starting shifting next run time.
This error also occurs if in idempiereMonitor click "StopAll" and then "StartAll".
Tested on iDempiere 3.1 and 5.1
Test case:
1) Add logging in AdempiereServerMgr:
public static class ServerWrapper implements Runnable {
private CLogger s_log = CLogger.getCLogger(getClass());
protected AdempiereServer server;
protected volatile ScheduledFuture<?> scheduleFuture;
public ServerWrapper(AdempiereServer server) {
this.server = server;
start();
}
public void start() {
s_log.warning("COLD START SCHEDULER: " + server.getName() + " sleep " + server.getSleepMS() + " nextRun " + server.getDateNextRun(false));
scheduleFuture = Adempiere.getThreadPoolExecutor().schedule(this, server.getInitialNap() * 1000 + server.getSleepMS(), TimeUnit.MILLISECONDS);
}
@Override
public void run() {
if (server.isSleeping()) {
s_log.warning("START SCHEDULER: " + server.getName() + " planTimeRun " + server.getDateNextRun(false));
server.run();
s_log.warning("PLANNING START SCHEDULER: " + server.getName() + " sleep " + server.getSleepMS() + " nextRun " + server.getDateNextRun(false));
scheduleFuture = Adempiere.getThreadPoolExecutor().schedule(this, server.getSleepMS(), TimeUnit.MILLISECONDS);
} else {
//server busy, try again after one minute
scheduleFuture = Adempiere.getThreadPoolExecutor().schedule(this, 60 * 1000, TimeUnit.MILLISECONDS);
}
}
2) Create new process "ProcessTest":
public class ProcessTest extends SvrProcess
{
@Override
protected void prepare()
{
//
}
@Override
protected String doIt() throws Exception
{
Thread.sleep(30000);
System.out.println("ProcessStart work");
return null;
}
}
3) Create scheduler for new process. Set interval to 3 minutes.
4) Reboot server
5) When scheduler is finished it is writing in console:
11:27:14 WARNING: START SCHEDULER: ProcessTest planTimeRun 2018-03-22 11:26:04.559
11:27:45 WARNING: PLANNING START SCHEDULER: ProcessTest sleep 180000 nextRun 2018-03-22 11:30:44.893
6) Go to idempiereMonitor and click "StopAll" and "StartAll"
7) In console will be written:
11:28:32 WARNING: COLD START SCHEDULER: ProcessTest sleep 180000 nextRun 2018-03-22 11:30:44.893
8) Sleep time does not recalculated. It must be equaled to "DateNextRun - CurrentTime".
If Sleep is negative, then scheduler must start from "server.getInitialNap() * 1000" (this formula works at server start if sleep <= 0)
In this test, the scheduler started after: "11:28:32" + "3min" + "server.getInitialNap() * 1000 (30s)" = 11:32:02
Correct start time: "11:28:32" + ("11:30:44" - "11:28:32") + "server.getInitialNap() * 1000 (30s)" = 11:31:00
11:32:02 WARNING: START SCHEDULER: ProcessTest planTimeRun 2018-03-22 11:30:44.893
If in idempiereMonitor "Reload" then "Sleep" was clicked it would be correct recalculation.
I found commits that eliminate a similar problem:
As you can see, this commits did not fully resolve described problem. I'm still working on it.
If someone had the same experience - share it with us, please.
Thanks.