Java 8 automatically using multicore?

五迷三道 提交于 2019-12-03 02:58:57
lbalazscs

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:

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

I have experienced this situation too. In my case, it is the frequent garbage collection that causes a significant high (98%) CPU usage. As pointed out by several comments under the original questions, the java GC uses multi-threading by default.

In my opinion, your program is not CPU bound. Therefore, it is not likely to fully use 4 cores. On the other hand, when there is not enough heap space allocated for your program, the frequent GC will easily exhaust the CPU resource. After increasing the heap size, everything is just fine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!