Why is creating a Thread said to be expensive?

前端 未结 6 2167
遇见更好的自我
遇见更好的自我 2020-11-22 09:34

The Java tutorials say that creating a Thread is expensive. But why exactly is it expensive? What exactly is happening when a Java Thread is created that makes its creation

6条回答
  •  暖寄归人
    2020-11-22 10:07

    Creating Threads requires allocating a fair amount of memory since it has to make not one, but two new stacks (one for java code, one for native code). Use of Executors/Thread Pools can avoid the overhead, by reusing threads for multiple tasks for Executor.

提交回复
热议问题