package multiThread;
/**
*
* @author qz:
* @version 创建时间:2019年10月10日 上午10:45:52
*
*/
public class ThreadSuspend {
public static void main(String[] args) {
// TODO Auto-generated method stub
final Hero gareen = new Hero();
gareen.name = "盖伦";
gareen.hp = 6160;
gareen.damage = 1;
final Hero teemo = new Hero();
teemo.name = "提莫";
teemo.hp = 3000;
teemo.damage = 1;
final Hero bh = new Hero();
bh.name = "赏金猎人";
bh.hp= 5000;
bh.damage = 1;
final Hero leesin = new Hero();
leesin.name = "李青";
leesin.hp = 3000;
leesin.damage = 1;
Thread t1 = new Thread() {
public void run() {
while (!teemo.isDead()) {
gareen.attackHero(teemo);
}
}
};
Thread t2 = new Thread() {
public void run() {
while (!leesin.isDead()) {
//临时暂停
Thread.yield();
bh.attackHero(leesin);
}
}
};
t1.setPriority(5);
t2.setPriority(5);
t1.start();
t2.start();
}
}
网友评论