Java Programming - Threads - Discussion
Discussion Forum : Threads - Finding the output (Q.No. 15)
15.
What will be the output of the program?
public class ThreadTest extends Thread
{
public void run()
{
System.out.println("In run");
yield();
System.out.println("Leaving run");
}
public static void main(String []argv)
{
(new ThreadTest()).start();
}
}
Discussion:
13 comments Page 2 of 2.
Kratika said:
9 years ago
Yield method only delays the current thread for some time or can it shift the priority.
Meghna said:
8 years ago
yield() basically means that the thread is not doing anything particularly important and if any other threads or processes need to be run, they should.
Otherwise, the current thread will continue to run.
Otherwise, the current thread will continue to run.
Sujata said:
8 years ago
Output is:
In run
Leaving run
Because, yeild() method only delays the current thread and gives the chance to same priority thread. In this case, there is no any thread present, so after some delay in will continue the execution.
In run
Leaving run
Because, yeild() method only delays the current thread and gives the chance to same priority thread. In this case, there is no any thread present, so after some delay in will continue the execution.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers