Does java code automatically utilize multiple processor cores if available(java 代码是否会自动利用多个处理器内核(如果可用))
问题描述
如果给定处理器上有多个内核可用,当 JVM 运行用户编写的 java 代码时,它们会自动使用吗?还是必须专门编写代码才能利用多核?
If multiple cores are available on a given processor, will they be utilized automatically when JVM runs a java code written by user? Or the code will have to be specifically written to take advantage of multi-core?
我的意思是,我们是否必须为 JVM 创建不同的代码才能在运行时利用多个内核,例如通过程序员在用户代码中创建多个线程?并且说如果我们在 java 代码中不使用多线程,那么无论有多少内核可用,JVM 都将无法利用多个内核.可能是这种情况——但我不确定.
I mean, do we have to create the code any differently for JVM to be able to take advantage of multiple cores while running it, say by means of the programmer creating multiple threads in the user code? And say if we don't use multi-threading in the java code, JVM won't be able to take advantage of multiple cores no matter how many cores are available. This might probably be the case -- but I am not sure.
推荐答案
在 java 中可以通过创建单独的线程来利用多核.与早期的 JVM 实现不同,现代实现创建了 OS 可以识别的本机线程,因此每个可用的处理器都可以分配给运行 java 程序中创建的每个线程.但是,这并不意味着您将始终获得多处理(多核利用)的优势. 这取决于问题以及解决方案的设计方式.设计不当的解决方案无法利用多核处理.
It's possible in java to take advantage of multi-core utilization, by creating separate threads. Unlike earlier implementations of JVM, modern implementations create native threads, which OS can recognize and thus, each available processor can be allocated to each thread created in running java program. But, that doesn't mean that you will always get the advantage of multiprocessing(multi-core utilization). It depends upon the problem and moreover, the way solution is designed. Improperly designed solutions doesn't take the advantage of multi-core processing.
注意:- 我的建议是,必须设计高度计算密集型作业,同时牢记并行计算(多核利用)架构.现代 CPU 已达到提高 CPU 时钟频率的最大极限.因此,像英特尔这样的公司正在设计具有多核的 CPU.因此,开发人员有责任编写软件以利用处理器的多核能力.
NOTE :- My suggestion is, Highly computation intensive jobs have to be designed keeping parallel-computing(multi-core utilization) architecture in mind. Modern CPUs have reached the maximum limit of increasing CPU clock frequency. Thus, companies like Intel are designing CPUs which have multi-cores. Thus, It's the responsiblity of developer to write software to take advantage of multi-core abilities of processor.
这篇关于java 代码是否会自动利用多个处理器内核(如果可用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:java 代码是否会自动利用多个处理器内核(如果可
基础教程推荐
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01