Discussion
Sample65 is run - what will be the output?
public class Sample65
{
static final Runnable POLITE = () ->
{
for (int spin = 0; spin < 3; spin++)
{
Thread.yield();
}
System.out.print("worker");
};
public static void main(String[] args) throws InterruptedException
{
Thread courteous = new Thread(POLITE);
courteous.start();
courteous.join();
System.out.print(" main");
}
}
Answer: A
yield is only a hint that the scheduler may ignore, and it never ends a thread or transfers control to a named one, however many times it is called. Whatever it does or does not do, the join still guarantees the worker finishes before main's print, so the order is fixed by the join alone.
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