views:

57

answers:

2
try{
  private synchronized void start() {
    if (threadStatus != 0)  
      throw new IllegalThreadStateException(); 
    group.add(this); 
    start0(); 
    if (stopBeforeStart) { 
      stop0(throwableFromStop); 
    } 
    this.run();
  } 
} catch( Exception e ) {
  System.out.println(e);
  //this code is giving error (start is not resolved).please resolve this issue.
}
}  
private native void start0();  
A: 

So what is a question?

endryha
this code is giving error (start is not resolved).please resolve this issue.
Anand
+3  A: 

That code is nonsensical. Java does not allow you to put a bare method declaration in a try block, or in any code block for that matter. In addition, your code seems to be trying to access the private methods and fields of java.lang.Thread. The Java compiler simply won't let you do that (unless you resort to nasty reflection hacks).

To override start you need to do something like this:

public class MyThread extends Thread {
    ...
    public static void start() {
       // your implementation of start goes here
       // somewhere you need to call super.start() ... because that's
       // the >>only<< sensible way to get the JVM to create the thread
       // stack and make the thread runnable.
    }
    ...
}

Finally, it should be noted that unless you are doing something really unusual, there is no need to override the start() method. The normal pattern for extending the Thread class is to override the run() method. And best practice is to instantiate the standard Thread class with a Runnable argument. Both approaches are illustrated in the javadocs.

Stephen C