After finally speaking to someone in Salesforce support who seemed to know what my point was, it was explained to me:
'Actual execution might be delayed based on service availability' means that the batch is enqueued for the interval initially set from the scheduleBatch method. 'Service availability' is not a reference to the concurrent batch count freeing up. This feature was not designed to manage the limit in question.
The rep also went on to explain that System.scheduleBatch
was provided only to remove the necessity to have an intermediate class that implements the Schedulable
interface and calls Database.executeBatch()
.
So, on that basis the documentation might better state:
• When you call Database.scheduleBatch
, Salesforce schedules the job
for execution at the specified time. Actual execution might be delayed
based on service availability, and if at that point of execution, there are no concurrent batch slots available, the job will not run at all (ever), nor will you be notified that it hasn't run.
This is not acceptable for my usage and I will not be able to make use of this function when a batch job absolutely must run, for this I will continue to use my own tried and tested pattern :)
With no parameters, new Map<KeyType, DataType>()
and new Map<KeyType, DataType> { }
have identical behavior. I tested a loop of 50,000 new maps of each and grabbed the timestamps from the logs, and they were almost consistently 64ms for 50,000 maps (we can't account for server load, however, so this performance may vary); approximately 0.001ms to create a new map either way.
The difference, however, is that each form has a different purpose. The parenthetical version is used to create a map from a list of SObject records or another map. They look like this:
Map<String, String> a = new Map<String, String>();
Map<String, String> b = new Map<String, String>(a);
Map<Id, SObject> c = new Map<Id, SObject>([SELECT Id,Name FROM Contact]);
The bracketed version is used to instantiate a map with values:
Map<String, String> a = new Map<String, String>{
'a' => '1',
'b' => '2',
'c' => '3' };
Best Answer
The performance of all Batch Apex (all asynchronous Apex, really) can vary based on system load. That applies regardless of whether the batch is enqueued immediately or with a time delay, based on the load when execution actually happens.
The extra wrinkle with
System.scheduleBatch()
is that scheduled job limits apply at the time of scheduling, while normal batch Apex limits are applied once the schedule fires and enqueues the batch job:You also don't have to implement
Schedulable
in your batch class if you're only using one-off scheduling withSystem.scheduleBatch()
.