Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

start, stop thread

807591Nov 9 2007 — edited May 14 2008
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 ?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 11 2008
Added on Nov 9 2007
16 comments
361 views