Know Your Execution Context

Lorenzo Barasti

15MWE December 2016

Table de Matières

  • What's an execution context?
  • CPU bound and IO bound operations
  • Which execution context should I use?
  • Conclusions

def executionContext

An Execution Context is an abstraction that lets us schedule and run tasks in a predictable way

(Some) Types of

Execution Context

  • FixedThreadPool
  • SingleThreadExecutor 
  • WorkStealingPool


 reuses a fixed number of threads operating off a shared unbounded queue

WorkStealingPool - fork/join

  • Dynamic number of threads up to a custom level
  • Multi-Queue
  • No guarantees on the order in which tasks will be executed


creates new threads as needed, but will reuse previously constructed threads when they are available

CPU/IO Bound Operations

CPU bound operations characterise tasks where we focus on computations - e.g. processing data

IO bound operations characterise tasks where we are waiting for data to be sent in or out of our process - e.g. http communication, DB reading/writing

Which EC should I use?

Let's settle it with some very unscientific...

Demo Time!


  • Look for the right EC for your use case
  • Avoid using the same execution context for different types of operations
  • Mind that in this context implementation matters
  • Tell your friends!


Know Your Execution Context

By Lorenzo Barasti

Know Your Execution Context

  • 794