Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread  RSS feed

 
Nimish Patel
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Have a good day...

to invoke child thread, we use start() method.

but this method call run() method , How it is possible ?

please give me advise..

Thanks in anticipation.

rgds,
Nimish
 
shank ram
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please clarify your objective, what is it that you want to know ?
 
Nimish Patel
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
i want to know that
when we apply start method on thread ,
how is it connected with run() method...

Thanks in anticipation..

rgds,
Nimish Patel
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In API about start method:

Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24216
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to "Threads and Synchronization" forum.
 
Rajesh Agarwal
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The start method is implemented to call the run method
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is quite a bit of complicated work involved in setting up a new thread. The start() method does all that tricky stuff, and then calls run(). When run returns, the start() method tears down the thread. We can happily ignore most of what start() does aside from calling run() on a new thread.

The run method is sometimes used other ways, which may or may not seem exactly "right" to everyone. For example, a thread pool or Timer works with Runnable objects and calls the run() method, but does not set up or tear down new threads for every run.

You could of course call the run method from another object yourself. The code would execute on the same thread as the caller, which is probably not what anybody wants. That just points out that there is no magic in run(). The hard work is out of sight in start().
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!