This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt regarding Threads? 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt regarding Threads?" Watch "doubt regarding Threads?" New topic
Author

doubt regarding Threads?

gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

When we create threads by implementing Runnable, You can pass a single Runnable instance to multiple Thread objects, so that the
same Runnable becomes the target of multiple threads, as follows :





i would like to know how to do the same thing by instantiating java.lang.Thread class. put in other words, how to start more than two threads that locks on the same object , when we extend Thread class to implement Thread behaviour. i hope you got my question ?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4342
    
    7

Well, you can always pass any object you want into your extended Thread classes if you give them an appropriate constructor.

But to be honest, implementing Runnable is almost always better than extending Thread anyway.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: doubt regarding Threads?
 
Similar Threads
Anonymous Issue
Runnable vs Thread
java threads
Creating multiple children threads
Using a single Runnable in multiple threads