• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

threads

 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1>when we want mixed output then we r overriding run() method and calling start() method.
2>when we directl call run() method control directly goes to run method in the class means no thread is getting created.
3>but if we override start() method and call it then is there be any new thread is created or same thread is continued.Is the call to start() method calls run() method or execute overriden start() method?
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know the answer to this but would like to add here==>
I do not think we ever acll start from a run method?
 
Dhanashree Mankar
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am not calling start method from run.
i am asking if a class is extending thread class and it has overrided
start() method and if we call start method like this
start();
then it will call run() method or overrided start method().and if it is calling start() then will it create new thread?
 
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi:
the overriden start method will not be called when you invoke <thread object>.start(). The new start method that you created in your own class will be invoked if you call it within an object of that class.
so it will not creat a new thread.
hope that help
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi dhanashree
Dhanashree : "1>when we want mixed output then we r overriding run() method and calling start() method."

What do you mean by mixed output? A thread is a thread of execution. You create a thread by overriding the run method and extending the thread class or implementing the Runnable interface.
2>when we directl call run() method control directly goes to run method in the class means no thread is getting created.
When you call run directly the method is executed and yes no thread is created unless you include a call to the Thread's start() method.
3>but if we override start() method and call it then is there be any new thread is created or same thread is continued.Is the call to start() method calls run() method or execute overriden start() method?

If the start method is overriden and it is called no thread would be created unless there is a call to Thread's start() method.
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could invoke a call to super.start() as the first statement in your overriddent start() method if you really really wanted to. But, before doing that, you may want to clearly define exactly what goal you want to accomplish, and analyze whether your approach will accomplish that goal.
Regards,
Jeff
 
reply
    Bookmark Topic Watch Topic
  • New Topic