Scheduling Flashcards

1
Q

How many threads can each CPU run at a time?

A

1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Is thread scheduling consistently applied or platform dependent?

A

Platform-dependent.

Java does not require implementations to schedule threads in a particular way.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

When must programmers be careful when coding with threads?

A

When the order of thread execution is vital to the overall program execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How does the JVM scheduler deal with threads of the same priority?

A

First-in-first-out

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How many states of threads are there?

A

4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the characteristics of the ‘new’ state?

A

Thread object created, but thread as such does not yet exist because ‘start’ has not yet been called

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the characteristics of the ‘runnable’ state?

A

After start, thread becomes ‘runnable.’
Default state for threads.
Many threads can be in ‘runnable’ state but only one per CPU will be executing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the characteristics of the ‘blocked’ state?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the characteristics of the ‘terminated’ state?

A

When a thread’s run method is finished, it moves to the terminated state.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How does the scheduler determine which thread to run?

A

From the number of threads in the runnable state, it will be the one with the highest priority.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What will the scheduler do when a higher priority thread enters the runnable state?

A

The scheduler will pre-empt the currently running executing thread and execute the new thread

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How does the schedulers deal with threads of the same priority?

A

Either run until blocked or terminate or possibly time-sliced.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How does starvation occur?

A

When a thread never manages to run.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How are shared resources dealt with when threads use them to ensure consistent and correct access to the shared data?

A

Locks

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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?

A

Priority Inheritance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is meant by task precedence?

A

Some threads need to execute before others to ensure for the correct execution of the program as a whole

17
Q

What are timing constraints?

A

In a real-time system, each thread may have its own deadline, some will take longer than others to complete, some may operate on a periodic basis

18
Q

What is priority inversion?

A

Where lower priority threads can execute and terminate before higher priority threads due to locks placed on resources making some threads unable to execute

19
Q

What is priority inheritance?

A

When a lower priority thread has a lock on a sync. resource which is required by a higher priority thread, the lower priority thread’s priority is temporarily and silently raised to allow it to finish and release the lock

20
Q

If threads of the same priority pre-empt each other, what is this known as?

A

Round-Robin scheduling

21
Q

Is round-robin scheduling required in JVM?

A

No

22
Q

Are Java threads fair?

A

No, higher priority threads will ensure lower priority ones will not if they are in the same pool

23
Q

In Java, with no round-robin scheduling, are threads of the same priority guaranteed to pre-emptively time-sliced?

A

No

24
Q

What happens if Round-Robin scheduling is used to deal with multiple threads of the same priority?

A

For all threads to complete it will take the same overall time.

25
Q

What happens if Round-Robin scheduling is not used to deal with multiple threads of the same priority?

A

One thread could be finished very early, and another would take a very long time.