import java.util.logging.Level;
import java.util.logging.Logger;
public class test {
private static void m1(final String a) {
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
System.out.print(a);
} catch (InterruptedException ex) {
Logger.getLogger(test.class.getName()).log(Level.SEVERE,
null, ex);
}
}
});
t1.start();
}
private static void m2(final String a) {
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
System.out.print(" " + a);
} catch (InterruptedException ex) {
Logger.getLogger(test.class.getName()).log(Level.SEVERE,
null, ex);
}
}
});
t2.start();
}
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
m1("Mihi");
m2("Cherub");
System.out.println("");
}
}
}
我想像 MihiCherub MihiCherub 同样输出 10 次
但现在我的输出是“MihiMihi Cherub CherubMihi CherubMihiMih”。我想同步我的两种方法,并希望得到 mihicherub 的结果。请帮忙..