理解java的本机线程和jvm [英] Understanding java's native threads and the jvm

查看:124
本文介绍了理解java的本机线程和jvm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道jvm本身就是一个将java可执行文件的字节码转换为本机机器代码的应用程序,但是当使用本机线程时,我有一些我似乎无法回答的问题。

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 questions that I just cannot seem to answer.


  • 是否每个线程都创建自己的
    jvm实例来处理他们的
    特定执行?

  • 如果然后,jvm必须有一些方法来安排它接下来将处理哪个线程,如果这样,这不会导致java的多线程性质无用,因为一次只能运行一个线程?

推荐答案


每个线程都创建自己的jvm实例来处理它们的特定执行?

Does every thread create their own instance of the jvm to handle their particular execution?

没有。它们在同一个JVM中执行,以便(例如)它们可以共享对象和类属性。

No. They execute in the same JVM so that (for example) they can share objects and class attributes.


如果没有那么jvm必须有一些方法来安排它接下来将处理哪个线程,如果是这样的话就不会渲染java的多线程性质没用,因为一次只能运行一个线程?

If not then does the jvm have to have some way to schedule which thread it will handle next, if so wouldn't this render the multi-threaded nature of java useless since only one thread can be ran at a time?

Java中有两种线程实现。本机线程映射到由主机OS实现的线程抽象。操作系统负责本机线程调度和时间切片。

There are two kinds of thread implementation in Java. Native threads are mapped onto a thread abstraction which is implemented by the host OS. The OS takes care of native thread scheduling, and time slicing.

第二种线程是绿色线程。这些是由JVM本身实现和管理的,JVM实现了线程调度。自Java 1.2以来,Sun / Oracle JVM尚未支持Java绿色线程实现。 (请参阅绿色主题与非绿色主题

The second kind of thread is "green threads". These are implemented and managed by the JVM itself, with the JVM implementing thread scheduling. Java green thread implementations have not been supported by Sun / Oracle JVMs since Java 1.2. (See Green Threads vs Non Green Threads)

这篇关于理解java的本机线程和jvm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆