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

查看:268
本文介绍了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 framework 以利用多个核心。

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

相关问题:

  • Is Multi-Threaded algorithm required to make use of Multi-core processors ?
  • Threads per Processor
  • Correctly multithreaded quicksort or mergesort algo in Java?

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

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