Thread scheduler is a part of the JVM. It decides which thread is executed first and which thread is executed next.
Only one thread is executed at a time.
We can't expect exact behavior of the thread scheduler it is JVM vendor dependent. So we can't expect output of the multithreaded examples we can say the possible outputs.
Thread Scheduler mainly uses preemptive (or) time slicing to schedule the threads.
Preemptive scheduling :
In this highest priority task is executed first after this task enters into waiting state or dead state then only another higher priority task come to existence.
Time Slicing Scheduling :
A task is executed predefined slice of time and then return pool of ready tasks. The scheduler determines which task is executed based on the priority and other factors.