利用多核的单线程程序 [英] Single thread program to make use of multiple cores

查看:92
本文介绍了利用多核的单线程程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java程序的单个线程能否自动利用CPU上的多个内核?

Can a single thread of a Java program automatically make use of multiple cores on the CPU?

推荐答案

Java程序的单个线程能否自动利用CPU上的多个内核?

Can a single thread of a Java program automatically make use of multiple cores on the CPU?

是,不是.单线程Java程序将使用多个线程,因为GC,JMX,终结器和其他后台线程可以在不同的CPU(CPU或内核)中运行.如果GC线程可以在另一个CPU中运行,则它们尤其可以显着提高性能.但是,您的单线程应用程序代码尽管可能在两个CPU之间移动,但永远不会同时在2个CPU中运行.

Yes and no. A single threaded Java program will use multiple threads in that the GC, JMX, finalizer, and other background threads can run in different CPUs (whether CPU or core). The GC threads especially give a significant performance boost if they can be running in another CPU. However, your single threaded application code, although it may move between CPUs, will never be running in 2 CPUs at the same time.

如何找出答案?

how to find out that?

这是一个很难回答的问题,它取决于您所运行的体系结构. * nix下的ps将能够显示您在运行队列中是否有多个线程,但是即使那样也可能无法显示它们实际上是在多个CPU中执行的.

That's a harder question and it depends on what architecture you are running on. ps under *nix will be able to show if you have multiple threads in the run queue but even then it may not show that they are actually executing in multiple CPUs.

这篇关于利用多核的单线程程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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