jvm使用多核cpu资源做了什么?

chr*_*phe 5 java multithreading multicore

通常一个java程序运行时只有一个名为"javaw"的进程.当我运行一个进程时,我只能获得一个核心(多核)的最大资源.但是当我在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();     
    }
}

}
Run Code Online (Sandbox Code Playgroud)

cdh*_*wie 7

一个进程的线程可以分布在不同的CPU和CPU核心上,就像单个进程一样.仅仅因为应用程序有一个进程并不意味着它的多个线程绑定到一个CPU /核心.