1

Does Java threads runs in parallel on Multi core Processor i.e, runs multiple threads at the same time?

[Parallel processing with Java Threads]

4
  • Also, even on a single CPU, a lot of threads are blocked on I/O wait, so it is useful to have multiple threads even without pre-emptive scheduling by the JVM (or operating system). Commented Jan 18, 2016 at 7:54
  • Possible duplicate of What does "volatile" mean in Java? Commented Jan 18, 2016 at 8:06
  • 2
    Don't change the entire question in-flight. First you were asking about the volatile modifier, and now you have completely removed that section from your question, even though you already had answers to it. Your question was: "How does volatile is useful in single core processor and does the primary purpose of volatile is to flush each of cpu cache values to in Memory" Commented Jan 18, 2016 at 8:52
  • Yes, I shouldn't have. Perhaps, i wanted to have main focus on parallelism Commented Jan 18, 2016 at 8:57

3 Answers 3

3

volatile is useful when you want to prevent your resource from being cached by Threads

Multiple threads can run on single CPU (though, one at a time) and can share resources, So volatile is still useful.

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

Comments

2

JVM does not decide the number of processors to be used. It is the job of OS. JVM has the capability of creating multiple threads and submits them.

Volatile is used to guarantee the data is not being fetched from CPU cache during concurrency.

Comments

0

First thing it's the JVM who spawns the threads but it's the hardware whom JVM depends on. If it has multi core, JVM can run multiple threads at the same time to extract max performance.

Now when it comes to user(You) decide to what extent you want to exploit the CPU resources and you do this through thread pools.(By defining max number of threads can run in parallel) but yet again you stuck up with your hardware configuration.

Comments

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.