• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

doubt on thread

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 242
Mac Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi debasmita pattnayak

When you are doing this

TSamp ts = new TSamp(this);
ts.start();



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){
super(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..

Regards..
 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
pie. tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic