标签:oid pack 先来 str except OLE static star ace
package com.shu.thread;
public class Race implements Runnable {
public static boolean isGameOver = false;
@Override
public void run() {
String name = Thread.currentThread().getName();
for (int i = 0; i < 100; i++) {
if (!isGameOver) {
System.out.println(name + " has run " + i + " steps.");
}else {
break;
}
if(i == 30 && name == "Rabbit"){
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (i == 99) {
isGameOver = true;
System.out.println(name + " wins!");
}
}
}
public static void main(String[] args) {
new Thread(new Race(), "Rabbit").start();
new Thread(new Race(), "Turtle").start();
}
}
标签:oid pack 先来 str except OLE static star ace
原文地址:https://www.cnblogs.com/archershu/p/12944130.html