Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

multithreading - Does java code automatically utilize multiple processor cores if available

If multiple cores are available on a given processor, will they be utilized automatically when JVM runs a java code written by user? Or the code will have to be specifically written to take advantage of multi-core?

I mean, do we have to create the code any differently for JVM to be able to take advantage of multiple cores while running it, say by means of the programmer creating multiple threads in the user code? And say if we don't use multi-threading in the java code, JVM won't be able to take advantage of multiple cores no matter how many cores are available. This might probably be the case -- but I am not sure.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As far as I know, the JVM does take advantage if the option exists. If you run the profiler tool: java/jdk[version]/bin/jvisualvm.exe you can observe how even a normal, "singled threaded" program makes use of multiple threads. I can't recall offhand if the profiler shows which cores are used for the given threads, though.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...