If you create and destroy flows over and over, then yes, it will tax and impose overheads. You can fix this using ThreadPool, which keeps the thread cache available for execution. Otherwise, threads are a way to go to processes.
You may think about practical architecture adjustments. For example, if you keep several streams alive for the sake of having an adaptive user interface (i.e., Wait for input), even if a particular stream will be used only after five menu transitions, then it may not be necessary to keep streams alive all the time. I rarely used 15 separate threads in a single application, even when this application ran a massive machine tool .... (I had repeated worker threads). Remember that threads still need to be scheduled, so you donβt need them uselessly.
Finally, make sure you are not facing the same old problems with a parallel program; avoid deadlocks, etc.
Ayubinator
source share