• Post Reply Bookmark Topic Watch Topic
  • New Topic

Class implementing Runnable and calling run() method  RSS feed

 
Vinny Menon
Ranch Hand
Posts: 62
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • 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
 
amod gole
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • 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: 62
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much for the reply Amod
cheers
vinny m
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!