I am a newbie using Java to do some data processing on csv files. For that I use the multithreading capabilities of Java (pools of threads) to batch-import the csv files into Ja
For many use cases, multithreading has less overhead than multiprocessing when comparing spawning a thread vs spawning a process as well as comparing communication between threads vs inter-process communication.
However, there are scenarios where multithreading can degrade performance to the point where a single thread outperforms multiple threads, such as cases severely affected by false sharing. With multiprocessing, since each process has its own memory space there is no chance for false sharing to occur and the multiprocessing solution can outperform the multithreading solution.
Overall, some analysis should be conducted when choosing a concurrent programming solution since the best performing solution can vary on a case-to-case basis. Multithreading cannot be assumed to outperform multiprocessing since there are counterintuitive situations where multithreading performs worse than a single thread. When performance is a major consideration, run benchmarks to compare single thread single process vs multithreading vs multiprocessing solutions to ensure you are truly gaining the performance benefits that are expected.
On a quick note, there are other considerations besides performance when choosing a solution.