Why is creating a Thread said to be expensive?

前端 未结 6 1905
遇见更好的自我
遇见更好的自我 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:12

    Obviously the crux of the question is what does 'expensive' mean.

    A thread needs to create a stack and initialize the stack based on the run method.

    It needs to set up control status structures, ie, what state it's in runnable, waiting etc.

    There's probably a good deal of synchronization around setting these things up.

提交回复
热议问题