class YieldTest
{
public static void main(String[] args) throws Exception
{
Demo d = new Demo();
Thread t = new Thread(d);
t.start();
//t.join();
for (int x = 0;x<100 ;x++ )
{
//Thread.yield();
System.out.println(Thread.currentThread().getName()+"---主线程");
Thread.yield();
}
}
}
class Demo implements Runnable
{
public void run()
{
for (int x = 0;x<100 ;x++ )
{
//Thread.yield();
System.out.println(Thread.currentThread().getName()+"---线程");
Thread.yield();
}
}
为什么不是主线程和0线程一对一的交替运行?