<div dir="ltr"><div>Does/will Stream.parallel() use virtual threads or stay with the Fork Join common pool threads?</div><div><br></div><div>Let's say I have a Stream where the "loop" is I/O bound.  Here is an example.<br></div><div><br></div><div>list.</div><div>   stream().</div><div>   parallel().</div><div>   map(MyClass::ioBoundOperation).</div><div>   ...<br></div><div><br></div><div>In Java 8, 11, and other pre-Java 21 versions, parallel() would use the Fork Join common pool to execute ioBoundOperation() in multiple threads.  If the list has many elements, then the Fork Join common pool will run out of threads since there are roughly N threads where N = the number of vCPUs.  Other parallel streams will then have to wait.  I hope I captured the situation correctly.<br></div><div><br></div><div>If parallel() uses virtual threads, then multiple parallel streams can execute and they won't block each other since the number of virtual threads can be very large.</div><div><br></div><div>Let's say parallel() uses virtual threads, would it make sense to always use parallel()?  I guess there is some small overhead for creating a virtual thread.  So, processing a small list with short CPU-bound operations may take more time than it saves.<br></div><div><br></div></div>