Originally posted by Anupam Sinha:
Hi Kaz
If you implement the start method that is override the start method then you are not putting a new thread into the ready state i.e. it would act like any other method and not function like the way the Thread.start() method should, unless you implicitly call the Thread's start() method within your overriden start() method. If you don't implement the run method then the Thread's class run method would be run which won't do anything but this is the case if you extend Thread if you implement Runnable you will have to implement run() method.
[ June 07, 2003: Message edited by: Anupam Sinha ]
I have the following code snippet in which MyThread class has overriden start() and run() methods. The overridden start() calls Thread's start() but this does not not behave like a thread of execution. Instead it behaves like any other method call.
class MyThread extends Thread {
String[] sa;
public MyThread(String[] sa) {
this.sa = sa;
}
public void run() {
System.out.print(sa[0] + sa[1] + sa[2]);
}
public void start() {
new Thread().start();
}
}
class ThreadQuiz {
private static String[] sa = new String[]{"X","Y","Z"};
public static void main (String[] args) {
Thread t1 = new MyThread(sa);
t1.start();
sa[0] = "A";
sa[1] = "B";
sa[2] = "C";
}
}
The output should be "ABC" when running as a real thread.