• 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

Thread

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to "Threads and Synchronization" forum.
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The start method is implemented to call the run method
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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().
 
Fire me boy! Cool, soothing, shameless self promotion:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic