Hello,
I'm trying to create a thread and to create my own start and stop methos as is showen in http://java.sun.com/j2se/1.5.0/docs/guide/misc/threadPrimitiveDeprecation.html.
But when I want to create the stop() methot my Eclipse says that it is not possible to redefine the final method stop of the Thread class. But in the example given on the link they use the redefinition of the stop method... So I'm little bit confused :) Can someone explain this?
Here is my code:
public class MyClass extends Thread {
private volatile Thread t;
public MyClass(){
//this is my constructor
}
public void start(){
t = new Thread(this);
t.start();
}
//here is my stop() method
public void stop(){
t = null;
}
public void run(){
Thread thisThread = Thread.currentThread();
while (t == thisThread) {
try {
thisThread.sleep(interval);
} catch (InterruptedException e){
}
//do something ...
}
}
}
May be instead of using extend Thread, I sould use the implement Runnable ?