ChineseHello.java
package threads;
public class ChineseHello extends Thread {
@Override
public void run() {
for (int i = 0; i < 10; i++) {
System.out.println("你好 "+i);
}
}
}
JapaneseHello.java
package threads;
public class JapaneseHello extends Thread {
@Override
public void run() {
for (int i = 0; i < 5; i++) {
System.out.println("ohayo "+i);
}
}
}
Test.java
package test;
import threads.ChineseHello;
import threads.JapaneseHello;
public class Test {
public static void main(String[] args) {
ChineseHello chineseHello;
JapaneseHello japaneseHello;
chineseHello = new ChineseHello();
japaneseHello = new JapaneseHello();
chineseHello.start();
japaneseHello.start();
for (int i = 0; i < 15; i++) {
System.err.println("main thread " + i);
}
}
}
来看结果,运行结果不唯一