Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

general question on threads?

 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
consider the code snippet given below :



here we are creating two threads and they are both targeting same runnable object viz "r". in other words both the threads are invoking code ON single runnable object. my question is how to do exaclty same thing if our class extends Thread class . in other words how to make 2 threads which invokes the run method of the same thread object??
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
change implements Runnable to extends Thread . that is the only change you required.
 
gurpeet singh
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please refer the link http://docs.oracle.com/javase/6/docs/api/java/lang/Thread.html#run(). the javadocs for the run() method says that



what does it mean by SEPARATE RUNNABLE RUN OBJECT ?

Second part of my question is that suppose i have following snippet of code :



as mentioned in comments, is "r" the separate runnable object the above javadoc is talking about ?

thirdly, if we have something like this



here what is target runnable ? is it t (since t also implements Runnable) ?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!