Thread States Flashcards
1
Q
(6 answers)
What are the different states in the six-state model?
A
-
NEW
- Thread has not yet started
-
RUNNABLE
- Thread is runnable (could be running or waiting for a resource)
-
BLOCKED
- Thread is waiting to enter a controlled region of code
-
WAITING
- Thread is waiting indefinitely for another thread to perform a particular action
-
TIMED_WAITING
- Thread is waiting for another thread to perform a particular action up to a specified time
-
TERMINATED
- Thread has run and has completed
2
Q
(5 answers)
What are the different Java methods relating to thread states?
A
-
Start
- Moves the thread into the RUNNABLE state
-
Run
- Thread begins executing code and either:
- Finishes and moves into the TERMINATED state
- Moves into the RUNNABLE state if it runs out of its allotted CPU time
- Thread begins executing code and either:
-
Yield
- Thread gives way to other threads of equal or higher priority, causing the thread to go back into the RUNNABLE state
-
Sleep
- Moves the thread into the TIMED_WAITING state
-
Join
- Causes the currently executing thread to wait until the thread on which the join is invoked has terminated
3
Q
Draw a diagram of the six-state model.
A