3:12 am - Friday April 19, 2019

Thread Example program for yield()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
/**Thread Example Program for yield()
* @author:Candidjava.com
* @description:It makes the currently excuted thread goes to ready state from running state
and allow other thread to execute
*/
class X implements Runnable
{
public void run()
{
System.out.println(Thread.currentThread());
Thread.yield();//It Causes the currently executing thread to temporarily pause and allow other threads to execute.
System.out.println(Thread.currentThread());
}
}
public class Yield
{
public static void main(String[] args)
{
X obj=new X();
Thread t1=new Thread(obj,"1st");
t1.start();
X obj1=new X();
Thread t2=new Thread(obj1,"2st");
t2.start();
}
}

Output:
Thread[1st,5,main]
Thread[2st,5,main]
Thread[1st,5,main]
Thread[2st,5,main]

Filed in: Z-A All Java Codes

Comments are closed.