Using scala.Future with Java 8 lambdas

The scala-java8-compat library provides interoperability between Scala 2.11 and Java 8 lambdas.


As @Seth mentioned you can use scala-java8-compat

import scala.concurrent.Future;
import static scala.compat.java8.FutureConverters.globalExecutionContext;
import static scala.compat.java8.JFunction.func;
...

Future<Object> future = ...;

future.onComplete(
    func(x -> ...), /// wraps Java lambda into a Scala Function
    globalExecutionContext());// Gets the global execution context.

However, Scala 2.12 introduced features to make it more compatible with Java, now you can use lambdas directly

Future<Object> future = ...;

future.onComplete(
    x -> ..., // Uses Java lambda directly
    globalExecutionContext()); // Gets the global execution context.

ExecutionContext.global basically is an execution context backed by a ForkJoinPool that manages a limited amount of threads.

If you need to get more information about it I recommend these two links

Execution Context in Futures

When in doubt, stick with scala.concurrent.ExecutionContext.global