how to use yield(),join() methods in program.where it is usefull in my program
0 Answer(s)      3 years and 10 months ago
Posted in : Java Beginners

Hi i am using yield() in my program but the out put i can't undrestand means i am using yield() and without yield() same out put print.But experts or some tutorials say yield() cause present executing thread and executes another thread with same priority .but in my example i can't findout exact function of yield(). Please any one clear my dought.

here my code is :

public class YieldDemo extends Thread { public void run(){ for(int i=1;i<=3;i++){ System.out.println("child thread"); Thread.yield(); } } public static void main(String[] args) { YieldDemo yd = new YieldDemo(); yd.start(); for(int i=1;i<=3;i++){ System.out.println("main thread"); } }


with and without yield() the same output will print

main thread main thread main thread child thread child thread child thread

please clear my dough with your own example how it works

thanks and regard naresh


View Answers

Related Tutorials/Questions & Answers: