Why we call Thread.start() method which in turns calls run method?

后端 未结 12 1125
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-29 01:40

Why do we call the thread object\'s start() method which in turns calls run() method, why not we directly call run() method?

12条回答
  •  爱一瞬间的悲伤
    2020-11-29 02:33

    [...] why not we directly call run() method?

    The run() method is just an ordinary method (overridden by you). As with any other ordinary method and calling it directly will cause the current thread to execute run().

    All magic happens inside start(). The start() method will cause the JVM to spawn a new thread and make the newly spawned thread execute run().

提交回复
热议问题