Java Backend Developer Interview Questions (Pt. 31–40)
31. What are the basic states of a thread?
NEW: The thread instance is newly created.
RUNNABLE: RUNNBALE has both READY and RUNNABLE states. When start() is invoked, the thread goes into READY state to wait for the system to allocate a timeslice.
RUNNING: The CPU allocates the time slice to the thread so the thread can execute.
BLOCKED: The thread is blocked when it tries to access some resource but the lock of that resource is acquired by other threads.
WAITING: The thread goes into waiting for the state until other threads notify or interrupt so it can re-enter Runnable state.
TIMED_WAITING: The thread goes into TIME_WAITING when the program puts a maximum timeout on the thread.
TERMINATED: The thread finishes and exits.
32. Why does it execute run() when we call start() instead of calling run() directly?
start() allows the thread to enter into a Runnable state. When the thread gets allocated time…