問(wèn)題描述
如果給定處理器上有多個(gè)內(nèi)核可用,當(dāng) JVM 運(yùn)行用戶(hù)編寫(xiě)的 java 代碼時(shí),它們會(huì)自動(dòng)使用嗎?還是必須專(zhuān)門(mén)編寫(xiě)代碼才能利用多核?
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 創(chuàng)建不同的代碼才能在運(yùn)行時(shí)利用多個(gè)內(nèi)核,例如通過(guò)程序員在用戶(hù)代碼中創(chuàng)建多個(gè)線(xiàn)程?并且說(shuō)如果我們?cè)?java 代碼中不使用多線(xiàn)程,那么無(wú)論有多少內(nèi)核可用,JVM 都將無(wú)法利用多個(gè)內(nèi)核.可能是這種情況——但我不確定.
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 中可以通過(guò)創(chuàng)建單獨(dú)的線(xiàn)程來(lái)利用多核.與早期的 JVM 實(shí)現(xiàn)不同,現(xiàn)代實(shí)現(xiàn)創(chuàng)建了 OS 可以識(shí)別的本機(jī)線(xiàn)程,因此每個(gè)可用的處理器都可以分配給運(yùn)行 java 程序中創(chuàng)建的每個(gè)線(xiàn)程.但是,這并不意味著您將始終獲得多處理(多核利用)的優(yōu)勢(shì). 這取決于問(wèn)題以及解決方案的設(shè)計(jì)方式.設(shè)計(jì)不當(dāng)?shù)慕鉀Q方案無(wú)法利用多核處理.
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.
注意:- 我的建議是,必須設(shè)計(jì)高度計(jì)算密集型作業(yè),同時(shí)牢記并行計(jì)算(多核利用)架構(gòu).現(xiàn)代 CPU 已達(dá)到提高 CPU 時(shí)鐘頻率的最大極限.因此,像英特爾這樣的公司正在設(shè)計(jì)具有多核的 CPU.因此,開(kāi)發(fā)人員有責(zé)任編寫(xiě)軟件以利用處理器的多核能力.
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.
這篇關(guān)于java 代碼是否會(huì)自動(dòng)利用多個(gè)處理器內(nèi)核(如果可用)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!