Java平台中的线程是否依赖? [英] Are Threads in Java platform dependent?

查看:171
本文介绍了Java平台中的线程是否依赖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很明显,OS调度/线程算法会对Java线程产生影响,但

It is obvious that OS scheduling/ threading algorithms have their impact on Java threads but

我们能否安全地说线程是OS /机器依赖的?

can we safely say that Threads are OS/machine dependant?

如果是这种情况,那么它是否会使Java平台依赖?

If this is the case then doesn't it make Java platform dependant?

推荐答案

是的,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.

这篇关于Java平台中的线程是否依赖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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