如何使Java使用计算机上的所有CPU能力? [英] how to make Java use all CPU power on a machine?

查看:119
本文介绍了如何使Java使用计算机上的所有CPU能力?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有时用Java编写代码,并且我注意到有时在多核计算机上使用100%以上的CPU。我现在在具有33个CPU(亚马逊的EC2)的多核计算机上运行一些代码,并且我想使我的Java进程使用所有可用的CPU,以使其具有很高的计算机利用率。这是可能的,还是由Java决定何时使用100%以上的CPU?我不想更改代码以使用多线程。

I sometimes write code in Java, and I noticed that sometimes it uses more than 100% CPU on a multicore machine. I am now running some code on a multicore machine that has 33 CPUs (Amazon's EC2), and I want to make my Java process use all CPUs available, so that it will have very high utilization of the machine. Is that possible, or is it left up to Java to decide when to use more than 100% CPU? I do not wish to change the code to use multithreading.

推荐答案

不使用多个线程或进程(或一个或多个线程或进程)进程正在运行),您将无法在 n 核心计算机上实现n * 100%的使用。

Without using multiple threads or processes (or something other than the one process running), you won't be able to achieve n*100% usage on a n-core machine.

操作系统决定在单个线程上运行每个用户程序,除非提出了更多请求。如果没有该请求,操作系统将很乐意让您在一个线程中运行代码,从而有可能使整个CPU的周期最大化-但这会使其他CPU保持开放状态。

The operating system decides to run each of your user programs on a single thread, unless a request for more is made. Without that request, the OS will happily let you run your code in a single thread, potentially maxing out an entire CPU's cycles - but it leaves the others open.

这篇关于如何使Java使用计算机上的所有CPU能力?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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