Let's say I have 2 threads a and b running inside the same process. The processor runs a few instructions from a, a few from b and so on until it reaches a line of code like this: Thread.sleep(1000).
The problem is that I don't really understand what the processor will do next. I suspect these 2 scenerios:
1)
2)
the 1000 milisecond interval is over so:
if the proccessor still runs code from Thread b
Which one resembles what's actually going on behind the scenes? If both are wrong then please indicate me the correct answer.
A lot of factors come into play, so it's tough to provide an absolute answer for your question.
But based on the available options you have given, #2 will be closest.
A different thread is invoked to run in case one of the following events occur:
....
A thread with a higher priority than the thread currently running enters the Runnable state. The lower priority thread is preempted and the higher priority thread is scheduled to run.
Here's the source.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With