wood burning stoves 2.0*
The moose likes Java in General and the fly likes why should we pass the object of the class implemented from runnable to thread class constructor? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "why should we pass the object of the class implemented from runnable to thread class constructor?" Watch "why should we pass the object of the class implemented from runnable to thread class constructor?" New topic
Author

why should we pass the object of the class implemented from runnable to thread class constructor?

shankara me
Greenhorn

Joined: Nov 30, 2012
Posts: 14
Hi my doubt is in java.My doubt is on creating thread by implementing runnable interface.
Please see the below programme.
In below programme I have implemented the class countdowneven from Runnable.
In main method I am passing the object of countdown even to constructor of thread class.
Why should we pass the object of countdowneven to constructor of thread class?
What operations will be performed by Thread class constructor on object of countdowneven?
-------------------------------------------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------------------------------------------------
Output:
10
8
6
4
2

Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
When you implement the Runnable interface, the class becomes a Runnable object. There is a constructor of the Thread class which accepts a Runnable parameter. When the start method is called on that thread, it will cause the run() method in the Runnable class to execute.
 
 
subject: why should we pass the object of the class implemented from runnable to thread class constructor?
 
Similar Threads
doubt in thread constructor..
doubt in wait() method.......
Doubt in the final !!
Threads doubt??
doubt in threads