Wednesday, February 25, 2009

source code to use of yieldmethod

// yield method is native method It depends Os ....
package
thread;

class MyThread extends Thread
{
public void run()
{
for(int i=0; i<=2 ;i++)
System.out.println("child thread");
Thread.yield();
}

}
public class ThreadDemo2
{
public static void main(String a[])
{
MyThread t = new MyThread();
t.start();
for(int i=0;i<=10;i++);
{
System.out.println("main thread");
}

}
}

Output:
child thread
child thread
child thread
main thread



0 comments:

Post a Comment