Java代码是否自动利用多个处理器核心(如果有) [英] Does java code automatically utilize multiple processor cores if available

查看:263
本文介绍了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的早期实现不同,现代实现创建本机线程,操作系统可以识别这些本机线程,因此,可以将每个可用的处理器分配给在运行的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代码是否自动利用多个处理器核心(如果有)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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