不确定我是否做对了。我需要创建一个新线程来写出一定次数的消息。我认为这到目前为止有效,但不确定它是否是最好的方法。然后我需要在线程完成运行后显示另一条消息。我怎么做 ?使用 isAlive() 吗?我该如何实施?
public class MyThread extends Thread {
public void run() {
int i = 0;
while (i < 10) {
System.out.println("hi");
i++;
}
}
public static void main(String[] args) {
String n = Thread.currentThread().getName();
System.out.println(n);
Thread t = new MyThread();
t.start();
}
}