关于Thread.stop()的问题!
白告 2004-07-13 08:52:29 For example, suppose your applet contains the following start, stop and run methods:
private Thread blinker;
public void start() {
blinker = new Thread(this);
blinker.start();
}
public void stop() {
blinker.stop(); // UNSAFE!
}
public void run() {
Thread thisThread = Thread.currentThread();
while (true) {
try {
thisThread.sleep(interval);
} catch (InterruptedException e){
}
repaint();
}
}
You can avoid the use of Thread.stop by replacing the applet's stop and run me
thods with:
private volatile Thread blinker;
public void stop() {
blinker = null;
}
public void run() {
Thread thisThread = Thread.currentThread();
while (blinker == thisThread) {
try {
thisThread.sleep(interval);
} catch (InterruptedException e){
}
repaint();
}
}
java文档中怎么可以overrride??!!
但我仿造他的做法总是报错:demoThreadgroup.java:17: stop() in demoThreadgroup cannot override stop() in java.lang.Thread; overridden method is final
既然stop()定义的是final为什么文档这么举例子?