Is multithreading faster than single thread?

前端 未结 2 463
遇见更好的自我
遇见更好的自我 2021-01-13 11:10

I want to check whether multithreading is faster than single thread,then I make a demo here:

public class ThreadSpeedTest {

    /**
     * @param args
     *         


        
2条回答
  •  遥遥无期
    2021-01-13 11:31

    1. There is absolutely a cost to creating additional threads. You should have a non-trivial amount of work needed before spinning up a new thread.
    2. I assume this means you have a quad-core CPU. The optimal number of threads actually depends on the workload, if threads are waiting for whatever reason they may be able to context switch to a another thread and you may see a benefit with a number of threads greater than the number of physical cores.
    3. I don't understand the question.

提交回复
热议问题