• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

general question on threads?

 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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) ?
 
All that thinking. Doesn't it hurt? What do you think about this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic