且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java平台中的线程是否依赖?

更新时间:2023-11-23 09:16:46

是的,Java中线程调度的细节取决于JVM实现和(通常)OS实现。

Yes, the details of the scheduling of threads in Java depends on the JVM implementation and (usually) on the OS implementation as well.

但是 Java SE规范中也没有指定该调度的细节,只指定了一些选定的基本规则。

But the specifics of that scheduling is also not specified in the Java SE specification, only a selected few ground rules are specified.

这意味着只要操作系统特定的调度符合这些基本规则,它也符合JVM规范。

This means that as long as the OS specific scheduling is conforming to those ground rules, it is also conforming to the JVM spec.

如果您的代码依赖于 not 中指定的计划细节JVM规范,然后它取决于实现细节,不能指望在任何地方工作。

If your code depends on scheduling specifics that are not specified in the JVM spec, then it depends on implementation details and can not be expected to work everywhere.

这是非常的mu与文件I / O的情况相同:如果您对路径进行硬编码并使用固定的目录分隔符,那么您的工作范围超出了规范,并且不能指望您的代码跨平台工作。

That's pretty much the same situation as file I/O: if you hard-code paths and use a fixed directory separator, then you're working outside the spec and can not expect your code to work cross-platform.

编辑: JVM 实现本身(即当然,JRE) 依赖于平台。它提供了允许纯Java程序不关心平台细节的层。为实现这一目标,JRE 必须特定于表格。

The JVM implementation itself (i.e. the JRE) is platform dependent, of course. It provides the layer that allows pure Java programs to not care about the platform specifics. To achieve this, the JRE has to be paltform specific.