When I use several threads in my Java application, dies the VM automatically run these threads on different cores?
Asked
Active
Viewed 2,335 times
1 Answers
4
The JVM isn't involved in that decision (any more, it was way back in Java 1.2). It's down to the OS now. So if you're using multiple threads, the OS can put them on different cores depending on its scheduling algorithms. (See also this question and its answers.)

Community
- 1
- 1

T.J. Crowder
- 1,031,962
- 187
- 1,923
- 1,875
-
So the best thing I can do is just use several Threads. And then the OS puts them on several cores if possible/needed. Is it the same with C++ applications? – MinecraftShamrock Dec 01 '13 at 19:36
-
@MinecraftShamrock It does matter which language you use, the OS schedules the threads, provided it uses native threads. – Peter Lawrey Dec 01 '13 at 19:37
-
@MinecraftShamrock: I'm afraid I don't know the state of the art with C++ apps and threads, the last time I dealt with threads in C++ was 17 years ago and I'm sure things have moved on since then. – T.J. Crowder Dec 01 '13 at 19:37
-
If it's only about multithreading / using several cpu cores, what would you choose? Java or C++ or some other language? – MinecraftShamrock Dec 01 '13 at 19:40
-
@MinecraftShamrock: I probably wouldn't base my decision on that, nearly all languages and environments support multiple threading and cores (one way or another). Other criteria would probably dominate the decision for me (what I was doing, the skills in the team, deployment, etc.). – T.J. Crowder Dec 01 '13 at 19:51
-
Okey. My last question on this topic: When I run multiple threads in C++, does the OS decide, on what core they go? – MinecraftShamrock Dec 01 '13 at 20:17
-
@MinecraftShamrock - of course, that is one reason it is there. – Martin James Dec 01 '13 at 22:53