• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

threads

 
Dhanashree Mankar
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • 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?
 
Shiwani Aggarwal
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • 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
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • 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.
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic