javaparallelstream

Can java parallel stream handle dependent tasks in a single thread


Let's say we have tasks 1-8, and we have 2 threads. Tasks 1-4 are allocated to thread 1 while tasks 5-8 are allocated to thread 2. It is possible to assign an execution sequence, for example, finish task 1 before starting task 2, task 2 will execute based on the output of task 1 for the tasks in the threads?


Solution

  • Nope. Java stream parallelism functions in a very specific way which gives it complete control, in particular requiring that it can decide how operations are executed and in what order.