Concurrency 2 : Thread Management Flashcards

1
Q

What are the 3 main threading issues encountered?

A

Deadlock, Livelock, Starvation

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

Define Deadlock…

A

When 2 or more threads are left waiting infinitely to proceed because they need resources that the other is using. This is known as the circular wait. E.g Thread A is waiting for Thread B and vice versa, thus neither can resume.

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

Define Livelock…

A

When 2 or more threads are stuck in a loop of transferring resources to one another. Thus, preventing them carrying out other tasks.

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

Define Starvation…

A

When one or more threads are waiting for a resource, but another thread is using the resource in an excessive way, thus starving the other threads of the resource.

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

On what class levels can thread management occur?

A

Object level and Thread level.

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

What are the 3 main object level thread management methods? Define each…

A

Must be in a synchronised block and do not need an invoking object.
wait() - Unlocks the objects monitor to allow other threads to enter the object.
notify() - Notifies the next waiting thread to resume execution.
notifyAll() - Notifies all waiting threads to resume execution.

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

What are the 3 main thread based thread management methods? Define each…

A

All are static methods, and can be invoked anywhere.
Thread.sleep() - Causes the current thread to pause for a specified amount of time.
Thread.join() - Makes the invoking thread wait for the completion of another thread.
Thread.yield() - Allows the thread to yield its usage of the processor so the processor can operate other threads of a higher priority.

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

What are the differences between wait() and Thread.sleep()?

A
  • wait() is object level and doesn’t need an invoking object
  • Thread.sleep() must be invoked from a synchronised block.
  • wait() is woken up by a notify call where as sleep() is woken by an interruption or time exceeded.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain the Thread lifecycle. Draw a diagram…

A

New - Thread is created.
Runnable - Thread is waiting for the OS to schedule its running.
Running - Thread is executing via the run() method.
Waiting/Sleeping/Blocking - Thread is waiting or sleeping until notified, in which case it goes back to the runnable stage.
Dead - Thread terminates.

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

Define Explicit Locking… How is it different from automatic locking…

A

Explicit locking enables us to create a lock object, and manually lock and unlock objects as we wish. This differentiates from synchronised since sync locks are invisible and automated.

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

Can we use explicit locking on more than one object?

A

Yes, we can create a lock and use it across multiple objects.

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