Java 如何利用多核? [英] How does Java makes use of multiple cores?

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

问题描述

JVM 在单个进程中运行,JVM 中的线程共享属于该进程的堆.那么JVM是如何利用多核提供多个OS线程来实现高并发的呢?

A JVM runs in a single process and threads in a JVM share the heap belonging to that process. Then how does JVM make use of multiple cores which provide multiple OS threads for high concurrency?

推荐答案

您可以使用多个线程来使用多个内核.但是使用比机器中存在的内核数量更多的线程可能只是浪费资源.您可以使用 availableProcessors() 获取内核数.

You can make use of multiple cores using multiple threads. But using a higher number of threads than the number of cores present in a machine can simply be a waste of resources. You can use availableProcessors() to get the number of cores.

Java 7 中有 fork/join 框架 以利用多核.

In Java 7 there is fork/join framework to make use of multiple cores.

相关问题:

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

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