自己写的一个测试小程序,望指教
- <p> <div class="blockcode"><blockquote>/** yield()暂停当前正在执行的线程对象,并执行其他线程
- */
- class Thread_yield extends Thread
- {
- Thread_yield(String name)
- {
- super(name);
- }
- public void run()
- {
- for(int i=0;i<100;i++)
- {
- System.out.println(getName()+": "+i);
- if(i%10==0)
- {
- yield();
- }
- }
- }
- }
-
- public class TestYield
- {
- public static void main (String[] args)
- {
- Thread_yield th_yield1= new Thread_yield("yield
- thread method 1");
- Thread_yield th_yield2= new Thread_yield("yield
- thread method 2");
- th_yield1.start();
- th_yield2.start();
- }
- }
复制代码
|
|