Does Java code automatically use multiple processor cores, if available

If multiple cores are available on a particular processor, will they be used automatically when the JVM runs Java code written by the user? Or should the code be specially written to use multi-core?

I mean, do we need to create code differently for the JVM in order to be able to use several cores during its launch, say, with the help of a programmer who creates several threads in the user code? And let’s say if we don’t use multithreading in Java code, the JVM will not be able to use multiple cores no matter how many cores are available. Perhaps this may be so, but I'm not sure.

+4
source share
2 answers

In java, you can use multicore usage by creating separate threads. Unlike previous JVM implementations, modern implementations create their own threads that the OS recognizes and, therefore, each available processor can be allocated for each thread created in a running java program. But this does not mean that you always get the advantage of multiprocessing (multi-core use). It depends on the problem and, moreover, the way to solve it. Improperly designed solutions do not take advantage of multicore processing.

. - , ( ). . , , Intel, . , , .

+3

, JVM , . : java/jdk []/bin/jvisualvm.exe, , , " " . , , .

+2

All Articles