6

I am curious to know is there any notable difference between Database.executeBatch vs System.scheduleBatch. One difference I know is, we can delay the batch execution in scheduleBatch method. However, I did not find any performance related documents.

Anyone have experienced any performance difference with these methods?

1 Answer 1

10

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:

All scheduled Apex limits apply for batch jobs scheduled using System.scheduleBatch. After the batch job is queued (with a status of Holding or Queued), all batch job limits apply and the job no longer counts toward scheduled Apex limits.

You also don't have to implement Schedulable in your batch class if you're only using one-off scheduling with System.scheduleBatch().

2
  • Thanks David! Which one you'd recommend to use,?
    – Ysr Shk
    Commented Jun 4, 2018 at 15:35
  • 1
    Use Database.executeBatch() unless you specifically need to delay the execution of the batch class. I never use System.scheduleBatch() myself.
    – David Reed
    Commented Jun 4, 2018 at 15:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .