RKCY
RKCY

Reputation: 4135

Threads concept in Java

I have a doubt.

There are 10 different threads in runnable state. Each having priority 1 to 10. How does the CPU schedules or executes these threads?

Upvotes: 0

Views: 872

Answers (3)

Peter Lawrey
Peter Lawrey

Reputation: 533492

It is worth noting, that windows ignores raised priorities, unless you are Administrator and on Linux all priorities are ignored unless you are root.

Generally, playing with thread priorities is not very useful.

Upvotes: 1

C. K. Young
C. K. Young

Reputation: 223003

Mainstream Java implementations use "native threads", which means that thread scheduling is done through the operating system. Java thread priorities simply map to OS-specific values. You should read your OS documentation to figure out what those levels mean, though. :-)

Upvotes: 1

Tony The Lion
Tony The Lion

Reputation: 63190

The OS has a thread scheduler that will (using an algorithm) decide based on priority and a few other factors, which thread will be run next. If you have a multi-core system, then each CPU can take a thread for it's account.

There's also the fact that a thread gets a slot of time, and then gets switched out for another thread and has to wait its turn again.

But thread scheduling is an Operating System function.

I hope that gives you an answer to your question.

Upvotes: 1

Related Questions