Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt regarding Threads?

 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic