强制多个线程在可用时使用多个CPU [英] Forcing multiple threads to use multiple CPUs when they are available

查看:157
本文介绍了强制多个线程在可用时使用多个CPU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个Java程序,它使用了很多CPU,因为它的性质。但是,它很多可以并行运行,我已经使我的程序多线程。当我运行它,它似乎只使用一个CPU,直到它需要更多,然后它使用另一个CPU - 是否有什么我可以在Java中强制不同的线程运行在不同的核心/ CPU?

I'm writing a Java program which uses a lot of CPU because of the nature of what it does. However, lots of it can run in parallel, and I have made my program multi-threaded. When I run it, it only seems to use one CPU until it needs more then it uses another CPU - is there anything I can do in Java to force different threads to run on different cores/CPUs?

推荐答案


当我运行它,它似乎只使用
一个CPU,直到它需要更多的
使用另一个CPU - 是否有什么I
可以在Java中强制不同的
线程在不同的
核心/ CPU上运行?

When I run it, it only seems to use one CPU until it needs more then it uses another CPU - is there anything I can do in Java to force different threads to run on different cores/CPUs?

我解释这部分你的问题意味着你已经解决了使你的应用程序多线程能力的问题。尽管如此,它不会立即开始使用多个核心。

I interpret this part of your question as meaning that you have already addressed the problem of making your application multi-thread capable. And despite that, it doesn't immediately start using multiple cores.

是有任何方式强制...的答案是(AFAIK)不直接。您的JVM和/或主机操作系统决定使用多少本地线程,以及这些线程如何映射到物理处理器。你有一些选项来调整。例如,我找到了此页面,其中介绍了如何调整Java在Solaris上的线程。而且此页面介绍了其他可能会降低多用户体验的因素,线程应用程序。

The answer to "is there any way to force ..." is (AFAIK) not directly. Your JVM and/or the host OS decide how many 'native' threads to use, and how those threads are mapped to physical processors. You do have some options for tuning. For example, I found this page which talks about how to tune Java threading on Solaris. And this page talks about other things that can slow down a multi-threaded application.

这篇关于强制多个线程在可用时使用多个CPU的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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