Java??3ì£o??3ìμ?μ÷?è-è?2?
ê±??:2011-02-20 51cto2??í leizhimin
??3ìμ?è?2?ê1ó?Thread.yield()·?·¨£?yield() ?a?2ì?·?·¨£?1|?üê??Yí£μ±?°?y?ú?′DDμ???3ì???ó£?2¢?′DD??????3ì?£
/**
*??Java??3ì£o??3ìμ?μ÷?è-è?2?
*
*??@author??leizhimin
*/
public??class??Test??{
???????????????? public??static??void??main(String[]??args)??{
???????????????????????????????? Thread??t1??=??new??MyThread1();
???????????????????????????????? Thread??t2??=??new??Thread(new??MyRunnable());
???????????????????????????????? t2.start();
???????????????????????????????? t1.start();
???????????????? }
}
class??MyThread1??extends??Thread??{
???????????????? public??void??run()??{
???????????????????????????????? for??(int??i??=??0;??i??<??10;??i++)??{
???????????????????????????????????????????????? System.out.println("??3ì1μú"??+??i??+??"′??′DD£?");
???????????????????????????????? }
???????????????? }
}
class??MyRunnable??implements??Runnable??{
???????????????? public??void??run()??{
???????????????????????????????? for??(int??i??=??0;??i??<??10;??i++)??{
???????????????????????????????????????????????? System.out.println("??3ì2μú"??+??i??+??"′??′DD£?");
???????????????????????????????????????????????? Thread.yield();
???????????????????????????????? }
???????????????? }
}
??3ì2μú0′??′DD£?
??3ì2μú1′??′DD£?
??3ì2μú2′??′DD£?
??3ì2μú3′??′DD£?
??3ì1μú0′??′DD£?
??3ì1μú1′??′DD£?
??3ì1μú2′??′DD£?
??3ì1μú3′??′DD£?
??3ì1μú4′??′DD£?
??3ì1μú5′??′DD£?
??3ì1μú6′??′DD£?
??3ì1μú7′??′DD£?
??3ì1μú8′??′DD£?
??3ì1μú9′??′DD£?
??3ì2μú4′??′DD£?
??3ì2μú5′??′DD£?
??3ì2μú6′??′DD£?
??3ì2μú7′??′DD£?
??3ì2μú8′??′DD£?
??3ì2μú9′??′DD£?
Process??finished??with??exit??code??0
3?′|£ohttp://lavasoft.blog.51cto.com/62575/221811 |