• Julian Depetris Chauvin
  • 0 Points
  • Member since 2015

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 1

While trying to debug some of my batch apex, i'm noticing that batches can run in parallel, whereas I used to think they always ran in sequence.


I have a batch job, that ends up consisting of 4 batches, i.e. 4 calls of execute().  Let's call the batches A, B, C, and D.  Their times of execution are noted below.


A runs from 14:51:16.017 to 14:51:16.067
B runs from 14:51:17.019 to 14:51:17.148
C runs from 14:51:17.019 to 14:51:17.108
D runs from 14:51:17.022 to 14:51:17.259

 These times are taken from debug logs, and you can see that B, C, and D run in parallel.


I was under the impression that these batches run serially.  Infact, the following post says that as well:


Filed a Case to ask this question, and got this response from Tech Support:
1. Is it possible for the execute() method to be running more than once at the same time? (I've already confirmed that the batch job was launched only once.)

All execute methods for batches within a batch job are synchronous so they will not "trip" over each other.

[posted at: http://boards.developerforce.com/t5/Apex-Code-Development/Batch-Apex-can-execute-invocations-run-concurrently/m-p/261857#M45628]


I'm hoping that this is true, that somehow you can have the batches run in sequence, but my experience above says otherwise.  Aftering performing timings with Database.stateful, I see that has no effect on the parallel execution of execute().


Anyone have any input on this topic?  Should I rewrite my batch job so that batches are not dependent of other batches?  Ideally, i'd like the batches to execute sequentially.



  • December 13, 2011
  • Like
  • 0