Understanding java's native threads and the jvm

前端 未结 4 1535
死守一世寂寞
死守一世寂寞 2020-12-13 02:52

I understand that the jvm is itself an application that turns the bytecode of the java executable into native machine code, but when using native threads I have some questio

4条回答
  •  鱼传尺愫
    2020-12-13 03:14

    A Java thread may be mapped one-to-one to a kernel thread. But this must not be so. There could be n kernel threads running m java threads, where m may be much larger than n, and n should be larger than the number of processors. The JVM itself starts the n kernel threads, and each one of them picks a java thread and runs it for a while, then switches to some other java thread. The operating system picks kernel threads and assigns them to a cpu. So there may be thread scheduling on several levels. You may be interested to look at the GO programming language, where thousands of so called "Goroutines" are run by dozens of threads.

提交回复
热议问题