通常,一个java程序运行时只有一个叫做“javaw.java”的.And进程,当我运行一个进程时,我只能得到一个核(多核)的最大资源。但是当我在jvm中运行一个多线程程序时,它使用的核心数量是根据线程的数量而定的,这超出了一个进程所能做到的范围。那么,谁能给我一些关于jvm如何在多核cpu机器上处理多线程程序的信息?
/**
* I run this program in my machine which has 8 core cpu
* and the jre is 1.6.0_24
* How does jvm use one process to use all the cpu resources?
*/
public class MultiCoreUseTest implements Runnable{
@Override
public void run() {
int i;
while(true)
i =1;
}
public static void main(String[] args) {
//create 8 threads
//8 threads the usage of cpu is 100%
// if 4 threads the usage of cpu is 50%
for(int i = 0; i<8; i++){
new Thread(new MultiCoreUseTest()).start();
}
}
}发布于 2012-10-08 14:41:45
一个进程的线程可以分布在不同的CPU和CPU核心上,就像单个进程一样。应用程序只有一个进程并不意味着它的许多线程都绑定到一个CPU/核心。
https://stackoverflow.com/questions/12776497
复制相似问题