package com.it;
/**
* 测试sleep()和yield()方法
*/
public class TestThreadCycle_Sleep_yield implements Runnable{
boolean live = true;//标记线程是否可以结束
@Override
public void run() {
int i =0;
while(i<10){
System.out.println(Thread.currentThread().getName()+":"+i++);
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// throw new RuntimeException(e);
// }
Thread.yield();//进入就绪状态
}
}
public void terminate(){
live = false;
}
public static void main(String[] args) {
TestThreadCycle_Sleep_yield tt = new TestThreadCycle_Sleep_yield();
Thread t = new Thread(tt);//新生状态
t.start();//就绪状态
for (int i = 0; i < 10; i++) {
System.out.println("主线程"+i);
}
// tt.terminate();//结束线程
System.out.println("tt线程结束");
}
}