Skip to content

async and sync execution

johnmcclean-aol edited this page Apr 8, 2015 · 1 revision

async() and sync() operators

async() and sync() can used to determine if subsequent tasks should be executed on the same thread as the completing task, or if they should be resubmitted to an Executor Service where they may be executed on a different thread. If async() is used the next tasks will be resubmitted for execution, if sync() is used the next tasks will be executed on the same thread as the completing task.

On a quad-core Mac Book Pro it is possible to do around ~335 million map operations per second in sync mode versus ~33 million in async mode. Use async to distribute work across threads (or for blocking operations) and sync to continue working efficiently on the completing thread. Benchmark for SimpleReact.

screen shot 2015-03-31 at 10 47 00 pm

A mix of async and sync execution. There is a performance overhead of submitting tasks to an ExecutorService - for non-blocking fast running code this should be avoided where possible.

screen shot 2015-03-31 at 10 47 06 pm

Typical aysnc execution where each completed task, triggers another task which submitted to an ExecutorService for execution.

Clone this wiki locally