Java 8 automatically using multicore?

后端 未结 2 543
天涯浪人
天涯浪人 2021-02-06 02:27

I did some tests a year ago concerning multicore with java 7. First I implemented some calculations only in the main thread (CPU usage showed that only one core did all the work

2条回答
  •  死守一世寂寞
    2021-02-06 02:52

    Java 8 does not automatically distribute the work on all CPU cores, unless your code requests it explicitly (for example by using parallel streams).

    In some special cases the Hotspot compiler will auto-vectorize the code, see for example JDK-6340864. However, automatic vectorization is using special SIMD CPU instructions, not multiple CPUs.

    Also see these answers:

    • Does the JVM have the ability to detect opportunities for parallelization?
    • Automatic parallelization

    (Note that I rewrote the answer, removing the part which was corrected by the comments)

提交回复
热议问题