File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt on thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt on thread" Watch "doubt on thread" New topic

doubt on thread

debasmita pattnayak
Ranch Hand

Joined: Apr 12, 2007
Posts: 94
hi ranchers,
below is the code which i ma unable to understand;

please explain the same...
this is not printing anything though its compiling and running fine

khushhal yadav
Ranch Hand

Joined: Jun 20, 2007
Posts: 242

Hi debasmita pattnayak

When you are doing this

TSamp ts = new TSamp(this);

You are invoking the run method of class Thread..
which by its implementation does nothing..

It's because though, you are using constructor of class TStamp
which takes a Runnable object as argument..
But that invokes the Thread() constructer of class Thread..
which is not taking that Runnable object as argument..
and calling it's own implemented run() method
So you are not getting anything on the console..

If you want the run() method of class Multi to be executed..
add this code to your class TStamp

TSamp(Runnable r){
This way you will be invoking the Thread(Runnable r) constructer of class
Thread.. And hence the run() method of Runnable object will be executed..

Hoping you have got something..


Manfred Klug
Ranch Hand

Joined: Jun 04, 2007
Posts: 377
Originally posted by khushhal yadav:
You are invoking the run method of class Thread.. which by its implementation does nothing..

That is not correct. The run method of the Thread class looks whether there is a Runnable-Object, and if yes the run method of the runnable is called. As result, something like this is possible.
I agree. Here's the link:
subject: doubt on thread
It's not a secret anymore!