Câu hỏi phỏng vấn Java
Câu hỏi

Explain the available thre...

Câu trả lời

In a high-level explanation, threads in a programming context can exist in several distinct states throughout their lifecycle. These states are critical for understanding how a thread interacts with the operating system and manages concurrency. Here are the primary thread states:

  1. New (Newborn) State: This is the state of a thread after it has been created but before its execution has started. The thread is considered alive but not yet eligible for running because it hasn't been started yet[1][3].

  2. Runnable (Ready-to-Run) State: Once the thread's start() method is invoked, it transitions to the runnable state. In this state, the thread may be running or ready to run whenever the CPU becomes available. The thread scheduler determines when the thread will actually execute[1][3][4].

  3. Running State: When the thread scheduler selects a thread from the runnable pool, it enters the running state. In this state, the thread is actively executing its code. A running thread can relinquish control voluntarily or be preempted by the scheduler to allow other threads to run[1][3].

  4. Blocked State: A thread can enter the blocked state if it is waiting to acquire a resource, such as a lock, that is currently held by another thread. The thread will remain blocked until the resource becomes available[1][3].

  5. Waiting State: Threads enter this state when they are waiting for another thread to perform a particula...

senior

senior

Gợi ý câu hỏi phỏng vấn

senior

Why is Spring MVC better than Servlets / JSP ?

junior

How HashMap works in Java?

senior

Explain Marshalling and Demarshalling

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào