Pools

object Pools
Since

15 Jun 2019

class Object
trait Matchable
class Any

Value members

Concrete methods

def availableCPUs[F[_]](implicit evidence$1: Sync[F]): Resource[F, Int]
def cached[F[_]](threadNamePrefix: String, daemons: Boolean)(implicit evidence$2: Sync[F]): Resource[F, ExecutionContextCT]

Cached pools should be used for blocking i/o. Without very stringent back-pressure and 100% certainty that you never overload with blocking i/o you will almost certainly freeze your application into oblivion by doing blocking i/o on a fixed thread pool.

Cached pools should be used for blocking i/o. Without very stringent back-pressure and 100% certainty that you never overload with blocking i/o you will almost certainly freeze your application into oblivion by doing blocking i/o on a fixed thread pool.

Value Params
daemons

whether or not the threads in the pool should be daemons or not. see java.lang.Thread#setDaemon(boolean) for the meaning for daemon threads.

threadNamePrefix

prefixes this name to the ThreadID. This is the name that usually shows up in the logs. It also prefixes "cached" to the names.

def fixed[F[_]](threadNamePrefix: String, maxThreads: Int, daemons: Boolean)(implicit evidence$3: Sync[F]): Resource[F, ExecutionContextFT]

The difference between this one and ExecutionContextMainFT is that this one allows to us to have a fixed thread pool with 1 thread.

The difference between this one and ExecutionContextMainFT is that this one allows to us to have a fixed thread pool with 1 thread.

N.B.: places where it is advisable to have a fixed thread pool:

  • the pool that handles incoming HTTP requests (thus providing some back-pressure by slowing down client requests)

  • the pool that handles the connections to your DB, thus back-pressuring your DB server.

As a side-note, you probably want your HTTP pool to be smaller than your DB pool (since you might be doing multiple DB calls per request).

Value Params
daemons

whether or not the threads in the pool should be daemons or not. see java.lang.Thread#setDaemon(boolean) for the meaning for daemon threads.

maxThreads

The maximum number of threads in the pool. Always defaults to 1 thread, if you accidentally give it a value < 1.

threadNamePrefix

prefixes this name to the ThreadID. This is the name that usually shows up in the logs. It also prefixes the maxThread count.

Returns

A fixed thread pool

def singleThreaded[F[_]](threadNamePrefix: String, daemons: Boolean)(implicit evidence$4: Sync[F]): Resource[F, ExecutionContextST]

A simple thread pool with one single thread. Be careful how you use it.

A simple thread pool with one single thread. Be careful how you use it.