• Post Reply Bookmark Topic Watch Topic
  • New Topic

Runnable Interface While Making a Thread  RSS feed

 
Tarun Oohri
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everybody
What i know is that to make a thread , we need a Thread class Object

I want to know how the following code functions. We are making an object of Thread class. In parameters we are suppose to pass the object of the class which implements Runnable interface. But here we are passing the object of interface... How can we make an object of an interface usng new keyword ?? How is this run() override here. Please explain me the code.

Thanks In Advance !!
 
vikram reddy bollu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Your understanding is correct as per below sentence.

We are making an object of Thread class. In parameters we are suppose to pass the object of the class which implements Runnable interface

And in the code it is happening in the same way. May be you are not aware of anonymous class implementation.

In the code, we are actually passing implementation of Runnable interface[Implementing run method, this way of implementation is called anonymous class] , not creating any object to Runnable interface.
 
Tarun Oohri
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Vikram for your feedback...i will go through anonymous class & shall try to understand in that prospective.
Regards!!!
 
Tarun Oohri
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vikram, i want to know that, such kind of making a thread and invoking a start() ... Does it confirm that the thread's run() will be invoked right after start() is executed ?

In the above code , ServerResponder & ServerResponseReader are classes which extends Runnable interface. Is it sure that run() of ServerResponder will be executed before that of ServerResponseReader class ?

Thanks In Advance
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tarun Oohri wrote:In the above code , ServerResponder & ServerResponseReader are classes which extends Runnable interface. Is it sure that run() of ServerResponder will be executed before that of ServerResponseReader class ?


No.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!