Will context-switching happen when thread changes its state?

chrisssss :

In java, will context switching happen when thread is changing its state?

I've googled a lot of sites, but did't find any article mentioned about this.

so if anyone can help would be appreciated.

like this:

doSomething();
//when Thread.sleep() is called, thread state will change from runnable to timed_waiting, so will context switching happen?
Thread.sleep(1000);
Marco R. :

Yes, sleep() triggers context switching to TIMED_WAITING.

See: https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.State.html#TIMED_WAITING

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=96329&siteId=1