What happens if a scheduled repeating job is taking longer time to finish than expected, thus missing next scheduled interval?
Depending on the amount of the delay and criterias for the schedule, the next execution of the job may either be delayed or completely cancelled, if the window of running the job has passed.
The kbmMW Scheduler contains some nice statistics to follow, which can be used to track if that happens, how often and provides some figures that tells about the time of executing.
The statistics can be obtained directly from the scheduled event instance you receive as result when you use Scheduler.Schedule…. But you can also iterate over all scheduled events. The following example iterates through the scheduled events, triggered by a TTimer, to be able to update a TMemo with statistics,.
procedure TForm1.Timer1Timer(Sender: TObject);
if not chbStats.Checked then
for i:=0 to lst.Count-1 do
mStats.Lines.Add(inttostr(i)+') ID='+e.ID+' Name='+e.Name+' Runs='+inttostr(e.Runs)+' Stalls='+inttostr(e.Stalls)+' TotalStalls='+inttostr(e.TotalStalls)+' LastRunTaken='+inttostr(e.LastRunTaken)+' TotalTimeTaken='+inttostr(e.TotalTimeTaken));
The scheduled events have a number of properties to access for statistics:
- Runs indicate how many times the event has run in total.
- Stalls indicate how many times the event should have run, but was unable to due to either still running or the thread pool exhausted at the time, since last time a successful run happened.
- TotalStalls counts total number of stalls.
- LastRunTaken shows how many mSecs last run lasted.
When TotalStalls increase fairly regularly it indicates that either too many events are defined compared to size of the relaxed thread pool (increase RelaxedPoolSize which is default 20), or some events are taking longer time than expected to run and thus can’t be timely rescheduled.