Hi I want to fix number of thread in ForkJoinPool
example ..
int parallelism = 2;
ForkJoinPool forkJoinPool = new ForkJoinPool(parallelism);
forkJoinPool.submit(() -> {
return IntStream.range(1,10).parallel().peek(i->{
System.out.println(Thread.currentThread().getName());
}).sum();
}).join();
Result----------
2021-01-28 16:56:57.103 INFO 12465 --- [ Test worker]
ForkJoinPool-1-worker-1
ForkJoinPool-1-worker-0
ForkJoinPool-1-worker-0
ForkJoinPool-1-worker-1
ForkJoinPool-1-worker-1
ForkJoinPool-1-worker-0
ForkJoinPool-1-worker-0
ForkJoinPool-1-worker-1
ForkJoinPool-1-worker-1
2021-01-28 16:56:57.297 INFO 12465 ---
It is Good but Using Redis(lettuce)
ValueOperations<String, Object> stringObjectValueOperations =
redisTemplate.opsForValue();
int parallelism = 2;
ForkJoinPool forkJoinPool = new ForkJoinPool(parallelism);
forkJoinPool.submit(() -> {
return IntStream.range(1,10).parallel().peek(i->{
stringObjectValueOperations.get("TEST");
System.out.println(Thread.currentThread().getName());
}).sum();
}).join();
}
--- Result
2021-01-28 17:04:01.867 INFO 13531 --- [ Test worker]
ForkJoinPool-1-worker-1
ForkJoinPool-1-worker-0
ForkJoinPool-1-worker-2
ForkJoinPool-1-worker-3
ForkJoinPool-1-worker-4
ForkJoinPool-1-worker-6
ForkJoinPool-1-worker-7
ForkJoinPool-1-worker-5
ForkJoinPool-1-worker-11
It is terrible ... non fixed thread
I guess Because it is Related Async&non-block of lettuce
But I don't know exactly
If Fixed Thread is possible, please give me an answer
But If Fixed Thread is impossible, please give me an exact reason .. I wander
question from:
https://stackoverflow.com/questions/65933355/how-to-fix-forkjoinpool-size-using-lettuce 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…