Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

why run() method in Runnable interface is not called ?

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The above program output is "MyThread ......"
Here my question is , when we start the Thread which is constructed based on Runnable target(see line1), why it is calling MyThread class run() method instead of calling RunnableClass run() method.
On line1 we are doing both (i.e extending thread and passing runnable target).
Explanation pls
Raju
(added code markers - B)
[ May 01, 2004: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you notice, nothing calls a "run" method in either class.
You can either extend a Thread, overriding its run method, or do what you did. But either way, you will end up instantiating a Thread and invoke its start method.
As for the reason: it's just the way it is.
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are overriding the run() method in MyThread class. That's why the Runnable run() has never executed.
Small change in MyThread would execute both of them.


Hope it helps
atanas
 
reply
    Bookmark Topic Watch Topic
  • New Topic