public Thread(ThreadGroup group,
Runnable target,
String name)
.....
.....
If the target argument is not null, the run method of the target is called when this thread is started. If the target argument is null, this thread's run method is called when this thread is started.
public void run()
If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.
Subclasses of Thread should override this method.
You are not mistaking the wording, but you forget that you have overwritten the run method.Originally posted by Murali Kakarla:
Or am I mistaking the wording of the API for run() method?
Originally posted by Manfred Klug:
You are not mistaking the wording, but you forget that you have overwritten the run method.
Since in your A class you have overridden the run method. As result, the run method of Thread is never called.Originally posted by Anupam Sinha:
the run method of the target class should run which is not happening in this case.
And as you have seen, the Thread.run() method calls the run method of the runnable. No call to Thread.run(), no call to Runnable.run().Originally posted by Murali Kakarla:
As I stated before, in API also they mentioned that run() method of the runnable target should be mentioned.
There is no overriding involved here. The Thread.run() method simply calls the run method of B.Originally posted by dhwani mathur:
Thread d=new Thread(new B());,this will override the method of Thread class
It's possible, but then your B class extends Thread which may not be desired. There is another possibility to use the run method of B. Simply call the run method of Thread from A's run method.But still have one doubt is it possible if we make A as super class and B extends A than well in the second statement will it override the method in class A and call run method of class B?
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |