How does Java run() method work?

后端 未结 4 704
陌清茗
陌清茗 2021-02-15 10:04

Multi-threading in Java is done by defining run() and invoking start().

Start delegates to a native method that launches a thread through operating system routines and

4条回答
  •  生来不讨喜
    2021-02-15 11:02

    Maybe it is a semantic argument, but a Thread and a Process are not synonymous.

    A process is launched by the operating system, and has it's own private code pages (compiled set of code). A Thread is launched from the program internals, and initially shares its parent's code pages (compiled set of code).

    That the JVM internally uses a Thread to run the main method is an implementation detail of the environment, but not a representation of the Java language. If a Thread was to report in the main stack frames, the architecture of referring back to the source code position would be impossible, because that main-serving thread would have no compilation unit (it is internal to the JVM).

提交回复
热议问题