Package javascalautils.concurrent
Contains utilities for concurrent/asynchronous programming.
The core principle is the
This is the handle the actual computation side of of the job uses.
The
The purpose is to have a placeholder for a value from an asynchronous computation.
The preferred way to get hold of the value-to-be is to register a listener on any of the provided listener types since this allows for asynchronous non-blocking operations.
The following image outlines an example of using a

This is done by using

Refer to the Javadoc for the classes or the Wiki for more details and examples:
https://github.com/pnerg/java-scala-util
The core principle is the
Promise
/Future
pattern which is the way to separate the execution/job side
(Promise
) from the client/receiver side (Future
). Promise/Future
In an essence thePromise
is the promise to deliver a value at
some time in the future.This is the handle the actual computation side of of the job uses.
The
Future
is the bearer of a value-to-be, an execution yet to
be finished. The purpose is to have a placeholder for a value from an asynchronous computation.
The preferred way to get hold of the value-to-be is to register a listener on any of the provided listener types since this allows for asynchronous non-blocking operations.
The following image outlines an example of using a
Promise
/Future
pair.
Executing a function
In addition to manually using theExecutor
class for performing
asynchronous computations one can let the Future
class deal
with that automatically. This is done by using
Future.apply
or
statically importing the FutureCompanion.Future
method from the companion class to the Future
. The execution path for the above example is illustrated in the picture below.import static javascalautils.concurrent.FutureCompanion.Future; Future<Integer> resultSuccess = Future(() -> 9 / 3); // The Future will at some point contain: Success(3) Future<Integer> resultFailure = Future(() -> 9 / 0); // The Future will at some point contain: Failure(ArithmeticException)

Refer to the Javadoc for the classes or the Wiki for more details and examples:
https://github.com/pnerg/java-scala-util
-
Interface Summary Interface Description Executable<T> A task that returns either a successful or failed result.Executor Executor service used to execute work in asynchronous fashion.ExecutorProvider Allows for creating a customExecutor
forExecutors.getDefault()
.Future<T> A Future that will hold the result of an asynchronous computation.Promise<T> The Promise is the promise to deliver a value at some time in the future. -
Class Summary Class Description Executors Factory for creatingExecutor
instances.FutureCompanion Acts as a Scala type companion object forFuture
.NamedSequenceThreadFactory Thread factory for providing meaningful names to the created threads.PromiseCompanion Acts as a Scala type companion object forPromise
.