Scheduling Flashcards
How many threads can each CPU run at a time?
1
Is thread scheduling consistently applied or platform dependent?
Platform-dependent.
Java does not require implementations to schedule threads in a particular way.
When must programmers be careful when coding with threads?
When the order of thread execution is vital to the overall program execution.
How does the JVM scheduler deal with threads of the same priority?
First-in-first-out
How many states of threads are there?
4
What are the characteristics of the ‘new’ state?
Thread object created, but thread as such does not yet exist because ‘start’ has not yet been called
What are the characteristics of the ‘runnable’ state?
After start, thread becomes ‘runnable.’
Default state for threads.
Many threads can be in ‘runnable’ state but only one per CPU will be executing
What are the characteristics of the ‘blocked’ state?
If thread calls sleep, wait or join, or if blocked when trying to read data or waiting for access to a lock on a synchronised object, it is moved to the blocked state.
What are the characteristics of the ‘terminated’ state?
When a thread’s run method is finished, it moves to the terminated state.
How does the scheduler determine which thread to run?
From the number of threads in the runnable state, it will be the one with the highest priority.
What will the scheduler do when a higher priority thread enters the runnable state?
The scheduler will pre-empt the currently running executing thread and execute the new thread
How does the schedulers deal with threads of the same priority?
Either run until blocked or terminate or possibly time-sliced.
How does starvation occur?
When a thread never manages to run.
How are shared resources dealt with when threads use them to ensure consistent and correct access to the shared data?
Locks
If a thread with a lower priority started to executed and obtained a lock on a shared resource but was then interrupted by a higher priority thread which also needed access to the locked resource, what would need to occur?
Priority Inheritance