Skip to content

Commit 46cfc4a

Browse files
committed
named executor failure fix #567
1 parent c9c0b3c commit 46cfc4a

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.jooby.issues;
2+
3+
import java.util.concurrent.Executors;
4+
5+
import org.jooby.assets.AssetsBase;
6+
import org.junit.Test;
7+
8+
public class Issue556 extends AssetsBase {
9+
10+
{
11+
executor("async", Executors.newFixedThreadPool(10));
12+
13+
get("/556/async", deferred("async", () -> "Async"));
14+
}
15+
16+
@Test
17+
public void async() throws Exception {
18+
request()
19+
.get("/556/async")
20+
.expect("Async");
21+
}
22+
23+
}

jooby/src/main/java/org/jooby/Jooby.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,8 @@ public EnvDep(final Predicate<String> predicate, final Consumer<Config> callback
691691

692692
private List<Consumer<Binder>> executors = new ArrayList<>();
693693

694+
private boolean defaultExecSet;
695+
694696
/**
695697
* Creates a new {@link Jooby} application.
696698
*/
@@ -2306,6 +2308,7 @@ public Jooby executor(final ExecutorService executor) {
23062308
* @return This jooby instance.
23072309
*/
23082310
public Jooby executor(final Executor executor) {
2311+
this.defaultExecSet = true;
23092312
this.executors.add(binder -> {
23102313
binder.bind(Key.get(String.class, Names.named("deferred"))).toInstance("deferred");
23112314
binder.bind(Key.get(Executor.class, Names.named("deferred"))).toInstance(executor);
@@ -2363,6 +2366,7 @@ public Jooby executor(final String name, final Executor executor) {
23632366
* @return This jooby instance.
23642367
*/
23652368
public Jooby executor(final String name) {
2369+
defaultExecSet = true;
23662370
this.executors.add(binder -> {
23672371
binder.bind(Key.get(String.class, Names.named("deferred"))).toInstance(name);
23682372
});
@@ -2483,8 +2487,8 @@ private Injector bootstrap(final Config args,
24832487
throw new IllegalStateException("Required property 'application.secret' is missing");
24842488
}
24852489

2486-
/** executors . */
2487-
if (executors.isEmpty()) {
2490+
/** executors: */
2491+
if (!defaultExecSet) {
24882492
// default executor
24892493
executor(MoreExecutors.directExecutor());
24902494
}

0 commit comments

Comments
 (0)