• 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

Class implementing Runnable and calling run() method

 
Ranch Hand
Posts: 63
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a class MyRunnable which implements Runnable interface.and i implement the run() method.
To make use of this class i will say:

My query is :
Can i do something like this:-


What will happen in this case? :roll:
will this method be run as a normal method without the threading feature?
Since Runnable provides only the body for the thread feature.(i.e. run())).
Thanks in advance for the answers.
and my apologies if this query has been asked earlier.
cheers
Vinny M
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Vinny Menon ,

their is no problem in calling run method using object of class which implements (or override)that run method.

but their is one difference between calling that method using object and
invoking run method using start method

when you call that method thats simple call that means control is transfered from main method to that method and then run method completes its execution and control is transfered back to main and main completes its execution. this is normal case or normal way of programming

but when you call that method using start
that means you are starting one thread and you hava orginally main thread now its totally dependent to select thread and excute that thread

thread means what its simple sub process and you can excute that two process with out context switching(for context switching refer o.s. books
 
Vinny Menon
Ranch Hand
Posts: 63
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks very much for the reply Amod
cheers
vinny m
 
reply
    Bookmark Topic Watch Topic
  • New Topic