object ExecutionContext
Contains factory methods for creating execution contexts.
- Source
- ExecutionContext.scala
- Alphabetic
- By Inheritance
- ExecutionContext
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
- final val defaultReporter: (Throwable) => Unit
The default reporter simply prints the stack trace of the
Throwableto System.err.The default reporter simply prints the stack trace of the
Throwableto System.err.- returns
the function for error reporting
- def fromExecutor(e: Executor): ExecutionContextExecutor
Creates an
ExecutionContextfrom the givenExecutorwith the default reporter.Creates an
ExecutionContextfrom the givenExecutorwith the default reporter.- e
the
Executorto use. Ifnull, a newExecutoris created with default configuration.- returns
the
ExecutionContextusing the givenExecutor
- def fromExecutor(e: Executor, reporter: (Throwable) => Unit): ExecutionContextExecutor
Creates an
ExecutionContextfrom the givenExecutor.Creates an
ExecutionContextfrom the givenExecutor.- e
the
Executorto use. Ifnull, a newExecutoris created with default configuration.- reporter
a function for error reporting
- returns
the
ExecutionContextusing the givenExecutor
- def fromExecutorService(e: ExecutorService): ExecutionContextExecutorService
Creates an
ExecutionContextfrom the givenExecutorServicewith the default reporter.Creates an
ExecutionContextfrom the givenExecutorServicewith the default reporter.If it is guaranteed that none of the executed tasks are blocking, a single-threaded
ExecutorServicecan be used to create anExecutionContextas follows:import java.util.concurrent.Executors val ec = ExecutionContext.fromExecutorService(Executors.newSingleThreadExecutor())
- e
the
ExecutorServiceto use. Ifnull, a newExecutorServiceis created with default configuration.- returns
the
ExecutionContextusing the givenExecutorService
- def fromExecutorService(e: ExecutorService, reporter: (Throwable) => Unit): ExecutionContextExecutorService
Creates an
ExecutionContextfrom the givenExecutorService.Creates an
ExecutionContextfrom the givenExecutorService.- e
the
ExecutorServiceto use. Ifnull, a newExecutorServiceis created with default configuration.- reporter
a function for error reporting
- returns
the
ExecutionContextusing the givenExecutorService
- final lazy val global: ExecutionContextExecutor
The explicit global
ExecutionContext.The explicit global
ExecutionContext. Invokeglobalwhen you want to provide the globalExecutionContextexplicitly.The default
ExecutionContextimplementation is backed by a work-stealing thread pool. It can be configured via the following scala.sys.SystemProperties:scala.concurrent.context.minThreads= defaults to "1"scala.concurrent.context.numThreads= defaults to "x1" (i.e. the current number of available processors * 1)scala.concurrent.context.maxThreads= defaults to "x1" (i.e. the current number of available processors * 1)scala.concurrent.context.maxExtraThreads= defaults to "256"The pool size of threads is then
numThreadsbounded byminThreadson the lower end andmaxThreadson the high end.The
maxExtraThreadsis the maximum number of extra threads to have at any given time to evade deadlock, see scala.concurrent.BlockContext.- returns
the global
ExecutionContext
- object Implicits
- object parasitic extends ExecutionContextExecutor with BatchingExecutor
WARNING: Only ever execute logic which will quickly return control to the caller.
WARNING: Only ever execute logic which will quickly return control to the caller.
This
ExecutionContextsteals execution time from other threads by having itsRunnables run on theThreadwhich callsexecuteand then yielding back control to the caller after *all* itsRunnables have been executed. Nested invocations ofexecutewill be trampolined to prevent uncontrolled stack space growth.When using
parasiticwith abstractions such asFutureit will in many cases be non-deterministic as to whichThreadwill be executing the logic, as it depends on when/if thatFutureis completed.Do *not* call any blocking code in the
Runnables submitted to thisExecutionContextas it will prevent progress by other enqueuedRunnables and the callingThread.Symptoms of misuse of this
ExecutionContextinclude, but are not limited to, deadlocks and severe performance problems.Any
NonFatalorInterruptedExceptions will be reported to thedefaultReporter.
This is the documentation for the Scala standard library.
Package structure
The scala package contains core types like
Int,Float,ArrayorOptionwhich are accessible in all Scala compilation units without explicit qualification or imports.Notable packages include:
scala.collectionand its sub-packages contain Scala's collections frameworkscala.collection.immutable- Immutable, sequential data-structures such asVector,List,Range,HashMaporHashSetscala.collection.mutable- Mutable, sequential data-structures such asArrayBuffer,StringBuilder,HashMaporHashSetscala.collection.concurrent- Mutable, concurrent data-structures such asTrieMapscala.concurrent- Primitives for concurrent programming such asFuturesandPromisesscala.io- Input and output operationsscala.math- Basic math functions and additional numeric types likeBigIntandBigDecimalscala.sys- Interaction with other processes and the operating systemscala.util.matching- Regular expressionsOther packages exist. See the complete list on the right.
Additional parts of the standard library are shipped as separate libraries. These include:
scala.reflect- Scala's reflection API (scala-reflect.jar)scala.xml- XML parsing, manipulation, and serialization (scala-xml.jar)scala.collection.parallel- Parallel collections (scala-parallel-collections.jar)scala.util.parsing- Parser combinators (scala-parser-combinators.jar)scala.swing- A convenient wrapper around Java's GUI framework called Swing (scala-swing.jar)Automatic imports
Identifiers in the scala package and the
scala.Predefobject are always in scope by default.Some of these identifiers are type aliases provided as shortcuts to commonly used classes. For example,
Listis an alias forscala.collection.immutable.List.Other aliases refer to classes provided by the underlying platform. For example, on the JVM,
Stringis an alias forjava.lang.String.