jvm使用多核cpu资源做了什么? [英] what does jvm do to use multicore cpu resource?

查看:184
本文介绍了jvm使用多核cpu资源做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常java程序运行时只有一个名为javaw的进程。当我运行一个进程时,我只能获得一个核心(多核)的最大资源。
但是当我在jvm中运行多线程程序时,它使用的核心数量是根据超出一个进程可以做的线程数量。那么有人能给我一些关于jvm如何处理多核cpu机器中多线程程序的信息吗?

Usually a java program is running with a single process called "javaw".And when I run a single process I can only get max resource of one core(of multicores). But when I run a multithread program in jvm, the number of cores it used is according to the number of threads which is beyond one process can do. So can anyone give me some information about how jvm deal with multithread program in multicore cpu machine ?

/**
* 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();     
    }
}

}


推荐答案

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

The threads of one process can be distributed across different CPUs and CPU cores, just as individual processes can. Just because an application has one process does not mean that its many threads are bound to one CPU/core.

这篇关于jvm使用多核cpu资源做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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