0

When two jobs are scheduled at the same time, will these two jobs execute at the same time(in parallel) or one after another (in sequence)?

2 Answers 2

2

As you already know, time of execution is not guaranteed. That said, they will each start as close to the scheduled time as the system can manage.

2
  • Let's say we have 100% of the service availability, and two different scheduled jobs scheduled at 12:30 PM. Are these two going to run at the same time? or when one is scheduled the service is not available anymore, therefore, the second job will need to wait? Nov 17, 2017 at 17:04
  • It doesn't work like that. You could likely run dozens of jobs at the same time before seeing noticeable lag. But regardless they are not executed to the second.
    – Adrian Larson
    Nov 17, 2017 at 17:59
2

I actually tested this by creating a 10 second job:

public class TenSecondSchedule implements Schedulable {
    public void execute(SchedulableContext context) {
        Long start = DateTime.now().getTime();
        while(DateTime.now().getTime()-start<10000);
    }
}

Then scheduled it twice:

System.schedule('Job 1', '0 28 10 * * ?', new TenSecondSchedule());
System.schedule('Job 2', '0 28 10 * * ?', new TenSecondSchedule());

And the jobs started and ended near each other:

10:28:00.0 (551106)|CODE_UNIT_STARTED|[EXTERNAL]|01p50000004bz5K|Job 2
10:28:10.12 (10016563991)|CODE_UNIT_FINISHED|Job 2

10:28:04.0 (683372)|CODE_UNIT_STARTED|[EXTERNAL]|01p50000004bz5K|Job 1
10:28:13.60 (10018027330)|CODE_UNIT_FINISHED|Job 1

Note that Job 2 actually started before Job 1, but there were still (approximately) six seconds left on Job 2 when Job 1 started.

Note that this is not guaranteed. In fact, you see that one job was four seconds off of the scheduled execution time (that "executes based on service availability clause"). However, assuming resources are available, they can run in parallel.

You must log in to answer this question.

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