Bee
Bee

Reputation: 12512

Java Threads in Real

I have a question about Java Threads. In java, while running on top of JVM, can threads run in parallel actually? Does JVM show OS each thread separately as they are? (enabling OS to run each Thread in multiple cores in the same time?) Or do they actually run interleaved only, as OS sees all threads as a one due to JVM? Hope my question is clear.

Upvotes: 2

Views: 903

Answers (2)

Peter Lawrey
Peter Lawrey

Reputation: 533530

I have a question about Java Threads. In java, while running on top of JVM, can threads run in parallel actually?

That is down to the OS and the hardware you have. However most JVMs on multi-core system can have threads running concurrently.

Does JVM show OS each thread separately as they are? (enabling OS to run each Thread in multiple cores in the same time?)

Most JVMs use the OS threads. In this case, there is no difference.

Or do they actually run interleaved only, as OS sees all threads as a one due to JVM?

Unless you have more than one thread needing to run (this is usually the case with most application) then only one thread will be running. In fact whenever your CPU load drops below one CPU, you have statically less than one thread running in your whole machine.

Upvotes: 2

dtech
dtech

Reputation: 14060

It depends on the implementation of the JVM. Modern implementation of JVM's expose Java threads to the OS.

Upvotes: 6

Related Questions