Java??3ì£o??3ìμ?μ÷?è-DY??
ê±??:2011-02-20 51cto2??í leizhimin
?aà?òa?÷è·μ?ò?μ?£?2?1ü3ìDò?±???′±àD′μ÷?è£????ü×?′ó?T?èμ?ó°?ì??3ì?′DDμ?′?Dò£???2??ü×?μ???×??????£
??3ìDY??μ???μ?ê?ê1??3ìè?3?CPUμ?×??òμ¥μ?×?·¨??ò?£???3ìDY??ê±oò£??á??CPU×ê?′??????????3ì£?ò?±??ü?????′DD£?μ±DY??ò??¨ê±??oó£???3ì?á??D?£???è?×?±?×′ì?μè′y?′DD?£
??3ìDY??μ?·?·¨ê?Thread.sleep(long millis) oíThread.sleep(long millis, int nanos) £??ù?a?2ì?·?·¨£???μ÷ó?sleepDY??μ???????3ì??£??òμ¥?μ£???????3ìμ÷ó?sleep£??íDY????????3ì?£
/**
*??Java??3ì£o??3ìμ?μ÷?è-DY??
*
*??@author??leizhimin
*/
public??class??Test??{
???????????????? public??static??void??main(String[]??args)??{
???????????????????????????????? Thread??t1??=??new??MyThread1();
???????????????????????????????? Thread??t2??=??new??Thread(new??MyRunnable());
???????????????????????????????? t1.start();
???????????????????????????????? t2.start();
???????????????? }
}
class??MyThread1??extends??Thread??{
???????????????? public??void??run()??{
???????????????????????????????? for??(int??i??=??0;??i??<??3;??i++)??{
???????????????????????????????????????????????? System.out.println("??3ì1μú"??+??i??+??"′??′DD£?");
???????????????????????????????????????????????? try??{
???????????????????????????????????????????????????????????????? Thread.sleep(50);
???????????????????????????????????????????????? }??catch??(InterruptedException??e)??{
???????????????????????????????????????????????????????????????? e.printStackTrace();
???????????????????????????????????????????????? }
???????????????????????????????? }
???????????????? }
}
class??MyRunnable??implements??Runnable??{
???????????????? public??void??run()??{
???????????????????????????????? for??(int??i??=??0;??i??<??3;??i++)??{
???????????????????????????????????????????????? System.out.println("??3ì2μú"??+??i??+??"′??′DD£?");
???????????????????????????????????????????????? try??{
???????????????????????????????????????????????????????????????? Thread.sleep(50);
???????????????????????????????????????????????? }??catch??(InterruptedException??e)??{
???????????????????????????????????????????????????????????????? e.printStackTrace();
???????????????????????????????????????????????? }
???????????????????????????????? }
???????????????? }
}
??3ì2μú0′??′DD£?
??3ì1μú0′??′DD£?
??3ì1μú1′??′DD£?
??3ì2μú1′??′DD£?
??3ì1μú2′??′DD£?
??3ì2μú2′??′DD£?
Process??finished??with??exit??code??0
′óé???μ??á1?ê?3??éò??′3?£??T·¨??×?±£?¤??3ì?′DD′?Dò?£
3?′|£ohttp://lavasoft.blog.51cto.com/62575/221790 |