I understand that java parallelStream(or ForkJoinPool) is designed to maximize CPU Utilization. Because of the great combination of java stream functional interfaces (such as map, reduce, filter) and ForkJoinPool I use java parallelstream and ForkJoinPool.
The problem is that ForkJoin does not limit the number of active thread. If some threads blocked while it hold large memory, ForkJoinPool tries to create more threads to meet the parallelism(running thread).
In this case cpu utilization will be maximized but heap memory will be Exhausted or even go OOM.
How can I limit the number of active threads of ForkJoinPool?
Or is there any java stream interface alternatives?