• 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
Sheriffs:
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
Bartenders:
  • Carey Brown
  • salvin francis
  • Piet Souris

Overriding the start method of Thread Class

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


What happens in the above code ?? I m not able to understand the fact of overriding the start() method of the thread class and still get an output of MyThread: start() followed by MyRunnable:run() Please can some one explain thank you
 
author
Posts: 23892
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dhruv Arya wrote:
What happens in the above code ?? I m not able to understand the fact of overriding the start() method of the thread class and still get an output of MyThread: start() followed by MyRunnable:run() Please can some one explain thank you



When you call, myThread.start(), you will get the "MyThread:start()" message.

When you call, thread.start(), the new thread will call the run() method of your runnable, and you will get the "MyRunnable:run()" message.

Henry
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Runnable interface has only one method, public void run(). Even if the runnable object has a public void start() method, it doesn't get into picture. But the if Thread object has a public void start() it does come into picture and affect how thread is submitted for run.
 
Dhruv Arya
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Alot I totally get my mistake you guys made my day Thank You
 
Hey cool! They got a blimp! But I have a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic