package pack10;
class Demo implements Runnable
{
public void run()
{
for(int x =0;x<100;x++)
{
System.out.println(Thread.currentThread().toString()+"...run.."+x);
Thread.yield();
}
}
}
class PriorityDemo10
{
public static void main(String[] args)throws Exception
{
Demo d=new Demo();
Thread t1=new Thread(d);
Thread t2=new Thread(d);
t1.start();
t2.start();
}
}
刚学到了优先级和yield(),在写yield()的练习时输出和视频里的有点不一样,当加了Thread.yield();这句时,t1和t2应该是交替执行的,可是我的输出有点不同,如图:
请指点下,谢谢!
|