function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
termfrequencytermfrequency 

Apex Threading model

Are apex apss single threaded in general, I'm not talking about future call.

 

 

Kirill_YunussovKirill_Yunussov

yea I want to know too.   Split up the logic into separate methods, and it seems to be running the methods in separate threads, so the result VF page loads before the results of the methods are calculated.

mulvelingmulveling

As far as the code you write in apex -- yes, it executes in single threaded fashion (at least from our perspective). When you have a Visualforce page with serveral ("N") expressions and an "action" method, then the order of execution is not guaranteed among those N + 1 entities -- that's not necessarily muli-threading, that's just non-deterministic (from our perspective) order of execution. Kind of annoying, since in some situations it would be nice to have the action method guaranteed to execute BEFORE the page expressions, so that you could perform a just-in-time redirect or DML op, etc.

 

One thing to keep in mind -- when you do a DML op (insert/update/delete) and then re-query on the affected tables, the results will reflect your previous DML op UNLESS you've invoked a getContent or getContentAsPDF method on a PageReference. Apex code executed as a result of those methods won't be able to see the "saved but not committed" changes to the database from the invoking Apex code, indicating that the getContent* code might be executed in a spawned separate thread, under the hood...

Macon RosterMacon Roster
aaaa