aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "threads" Watch "threads" New topic
Author

threads

Dhanashree Mankar
Ranch Hand

Joined: Aug 25, 2003
Posts: 123
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

Joined: Aug 21, 2003
Posts: 22
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

Joined: Aug 25, 2003
Posts: 123
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

Joined: Aug 20, 2003
Posts: 532
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


SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
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

Joined: Jul 30, 2003
Posts: 804
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


Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: threads