1

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.
  • 2,667
  • 15
  • 33
chrisssss
  • 35
  • 1
  • 5
  • 1
    Yes. Most current implementation will tell OS that tread is sleeping and context can be switched. – talex May 15 '19 at 09:13

1 Answers1

1

Yes, sleep() triggers context switching to TIMED_WAITING.

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

Marco R.
  • 2,667
  • 15
  • 33