How do I increase the thread count while using thread pool my code is as follows,
@SpringBootApplication
@EnableReactor
public class Application implements CommandLineRunner {
@Autowired
private Reactor reactor
@Bean
Reactor createReactor(Environment env) {
return Reactors.reactor()
.env(env)
.dispatcher(Environment.THREAD_POOL)
.get();
}
Adding the following code did not increase the thread count, which is fixed by default to the number of cores on the machine.
@Bean
public AsyncTaskExecutor workQueueAsyncTaskExecutor(Environment env) {
return new WorkQueueAsyncTaskExecutor(env)
.setName("workQueueExecutor")
.setBacklog(2048)
.setThreads(20)
.setWaitStrategy(new YieldingWaitStrategy());
}
How do I set the thread count for my reactor variable?
If I remove the createReactor
bean, the reactor works fine, it's just that the default is RingBuffer
single thread. With that bean and the specification of THREAD_POOL
, threads equal to the number of cores on the machine are launched.
I am just trying to see how I can increase that count manually...
Thanks
it was answered by @jbrisbin on gitter, https://gitter.im/reactor/reactor?at=5548f40f52bceea22c3814e0
just for convenience, the answer is to create a bean for the dispatcher and refer to it from the reactor creation bean
@Bean
Reactor createReactor(Environment env) {
Reactor r = Reactors.reactor().env(env).dispatcher(createDispatcher()).get();
return r;
}
@Bean
Dispatcher createDispatcher() {
Dispatcher d = new WorkQueueDispatcher("multThreadedQueueDispatcher", 20, 2048, null);
return d;
}