Skip to content

Commit 7a06aab

Browse files
Add support for size property in executors.
1 parent 75e4551 commit 7a06aab

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

  • jooby-executor/src/main/java/org/jooby/exec

jooby-executor/src/main/java/org/jooby/exec/Exec.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.List;
2828
import java.util.Map;
2929
import java.util.Map.Entry;
30+
import java.util.Optional;
3031
import java.util.Set;
3132
import java.util.concurrent.Executor;
3233
import java.util.concurrent.ExecutorService;
@@ -186,8 +187,18 @@ public class Exec implements Module {
186187
ImmutableMap
187188
.of(
188189
"cached", (name, n, tf, opts) -> Executors.newCachedThreadPool(tf.get()),
189-
"fixed", (name, n, tf, opts) -> Executors.newFixedThreadPool(n, tf.get()),
190-
"scheduled", (name, n, tf, opts) -> Executors.newScheduledThreadPool(n, tf.get()),
190+
"fixed", (name, n, tf, opts) -> {
191+
Optional<Integer> size = Optional.ofNullable(
192+
opts.containsKey("size") ? Integer.parseInt(opts.get("size").toString()) : null
193+
);
194+
return Executors.newFixedThreadPool(size.orElse(n), tf.get());
195+
},
196+
"scheduled", (name, n, tf, opts) -> {
197+
Optional<Integer> size = Optional.ofNullable(
198+
opts.containsKey("size") ? Integer.parseInt(opts.get("size").toString()) : null
199+
);
200+
return Executors.newScheduledThreadPool(size.orElse(n), tf.get());
201+
},
191202
"forkjoin", (name, n, tf, opts) -> {
192203
boolean asyncMode = Boolean.parseBoolean(opts.getOrDefault("asyncMode", "false")
193204
.toString());

0 commit comments

Comments
 (0)