1

I read somewhere sometime that we should have one JVM per core. I also read that Java is not good with multiple cores or CPUs hence scala is preferred.

Recently on a link I read that multiple threads do execute in different core if available.

Questions:

  1. does JVM takes multiple cores/CPUs in consideration and execute each thread in separate core if available?
  2. usage of scala for better usage of cores is somewhat different that just execution in separate core?
  3. if JVM executes each thread in separate core (if available) what is the meaning of one JVM per core, with a single JVM I can utilize all the cores.
  4. if answer to 1 is yes, what is the use of deploy a war/ear in multiple instances of server running in same machine.
4
  • 1
    I don't quite understand.. JVM forwards all calls to native OS. How does multiple cores / Single core directly matter to it? Commented Jul 9, 2014 at 14:30
  • @TheLostMind - it does matter. In Python the GIL prevents multiple cores from being used simultaneously, even though it can execute on any single core at a given time, so this question is relevant. Commented Jul 9, 2014 at 14:34
  • Related: stackoverflow.com/questions/4436422/… Commented Jul 9, 2014 at 14:38
  • 1
    Can you source (and date) the affirmation that "one JVM per core"? I have been executing multiple threads on multiple cores without any special intervention since JDK 1.5... (multi-core machines were not so widespread before that) Commented Jul 9, 2014 at 14:50

1 Answer 1

4
  1. Yes. Actually, all JVMs, nowadays, use native threads. So the thread scheduling and distribution across cores is done by the OS, not by the JVM.

  2. Scala executes on the JVM, just as Java. So there is no difference in how threads use cores between Java and Scala

  3. There is no reason to have one JVM per core. You could want that to avoid using two much memory per JVM, or to be able to go for version 1 to version 2 without having any service interruption, but that is a different matter.

  4. No reason linked to multithreading problems. As I said, you might want to have two JVMs to be able to shutdown one without having any service interruption, or to isolate two versions of the same app for different customers for example. But that has nothing to do with multithreading.

Sign up to request clarification or add additional context in comments.

4 Comments

You mean to say that the JVM can directly decide how to execute threads?
No, quite the contrary. The thread scheduling is done by the OS.
Then- How does multiple cores / Single core directly matter to it?
I'm not sure what you mean by that. But it matters because some race conditions and visibility issues can only happen if multiple cores are used. So the Java Memory Model must take multiple cores into account (and it does).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.