/*
出现问题: 在使用Thread.yield() 后两个线程并未交替运行。
*/
class YieldDemo
{
public static void main(String[] args)
{
Join j = new Join();
Thread t1 = new Thread(j);
Thread t2 = new Thread(j);
t1.start();
t2.start();
}
}
class Join implements Runnable
{
public void run()
{
int x=0 ;
while (x++<50)
{
System.out.println(Thread.currentThread().toString()+".....run"+x);
Thread.yield();
}
}
} |