Discussion
Sample55 is run - what will be the output?
public class Sample55
{
static final Object GATE = new Object();
public static void main(String[] args) throws InterruptedException
{
Thread t = new Thread(() ->
{
synchronized (GATE)
{
try { GATE.wait(); } catch (InterruptedException e) { }
}
});
t.start();
Thread.sleep(200);
System.out.println(t.getState());
synchronized (GATE) { GATE.notifyAll(); }
}
}
Answer: C
An untimed wait puts the thread in the wait set indefinitely, which is reported as WAITING. It is not BLOCKED, because it is not competing for a lock at that moment; it released the monitor when it called wait and will contend for it again only once notified.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development