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.
相关文章