public enum ExecutionMode extends Enum<ExecutionMode>
Enum Constant and Description |
---|
DEFAULT
Default execution mode.
|
EVENT_LOOP
Execute route handler in the event loop thread (non-blocking).
|
WORKER
Execute handler in a worker/io thread (blocking).
|
Modifier and Type | Method and Description |
---|---|
static ExecutionMode |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static ExecutionMode[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final ExecutionMode EVENT_LOOP
{
mode(EVENT_LOOP);
get("/non-blocking", ctx -> "I'm running on event-loop thread (no blocking allowed)");
// Dispatch to worker thread, blocking routes
dispatch(() -> {
get("/blocking", ctx -> {
// remote call: service, database, etc..
return "Safe to block";
});
});
}
public static final ExecutionMode WORKER
{
mode(WORKER);
get("/worker", ctx -> {
// remote call: another service, database, etc..
return "Safe to block";
});
}
public static final ExecutionMode DEFAULT
EVENT_LOOP
and WORKER
.
If route handler returns a `reactive` type, then Jooby run the route handler in the event-loop
thread. Otherwise, run the handler in the worker thread.
A reactive type is one of:
- CompletableFuture
.
- A reactive stream Publisher
- Rx types: Observable, Flowable, Single, Maybe, etc..
- Reactor types: Flux and Mono.
Examples:
{
get("/non-blocking", ctx -> {
return CompletableFuture.supplyAsync(() -> {
return "I'm non-blocking";
});
});
get("/blocking", ctx -> {
return "I'm blocking";
});
}
public static ExecutionMode[] values()
for (ExecutionMode c : ExecutionMode.values()) System.out.println(c);
public static ExecutionMode valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullCopyright © 2020. All rights reserved.