说我有:
class WriteThread extends Thread {
char letter;
boolean stop = false;
WriteThread(char letter) {
this.letter = letter;
}
public void halt() { stop = true; }
public void run() {
while(!stop) { System.out.print(letter); }
}
}
和:
WriteThread a = new WriteThread('a');
WriteThread b = new WriteThread('b');
a.start();
b.start();
// do some other stuff
a.halt();
b.halt(); // (*)
执行 (*) 时是否保证两个线程都停止?(停止是指在 (*) 之后不再有打印)