Scheduling Flashcards
What does Thread Scheduling deal with?
Thread scheduling deals with allocating threads to CPUs and deciding how long each thread will execute.
Give a brief descrirtion of a thread when it is in a New State
A thread object has been created, but the thread as such does not yet exist because ‘start’ has not been called yet.
Give a brief descrirtion of a thread when it is in a Runnable State
After ‘start’ has been called on a thread it moves into the ‘runnable’ state – this is the default state for a thread. Many threads might be in the ‘runnable’ state but only one (per cpu) will actually be executing. (The scheduler determines which threads will actually ‘run’).
Give a brief descrirtion of a thread when it is in a Blocked State
If a thread executes a sleep(), wait(), or join() method, or when it is blocked when trying to read data, or when it is waiting for a lock on a synchronized object, it moves into the ‘blocked’ state. When it unblocks, it moves into the runnable state.
Give a brief descrirtion of a thread when it is in a Terminated State
When a thread’s run() method finished it moves to the terminated state (i.e. the ‘thread’ terminates).
Name atleast one situation where the schedular will run a different thread
One of the currently executing threads exits the Runnable state, i.e. it enters the blocked state (via a ‘wait’ or ‘sleep’ or ‘yield’ etc.) or it terminates.
A higher priority thread than one of the currently running threads enters the Runnable state. The lower priority thread is preempted and the higher priority thread is run.