splitting work into 2 threads is an artificial limitation, and like any limitation associated with art, it can only limit the level of parallelism. If two parts are logically sequential (for example, io operation should precede intensive processor operation to provide data), then they should be executed sequentially in one thread. If you have several independent tasks, they must be performed in different threads. Problems can arise if you have thousands of threads and they eat too much memory. Then you need to separate the work in the tasks and complete these tasks in the thread pool (executing service). This is a more complex approach, as you may need to agree on the beginning of your tasks, but there are no standard tools for this. One of the solutions for coordinating small tasks is the actor’s execution model, but you can’t say in advance if the actor’s model meets your needs.
source share