• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Why doesnt the run() method have reference to the calling thread

 
Ranch Hand
Posts: 198
Oracle Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone explain the sentence that the run method doesnt have reference to the calling thread
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The run method is a simple method with no arguments, why should it have a special reference to it's running Thread? You can always get one via Thread.currentThread() if you wanted one.
 
author
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think Ragi is asking about the thread that called start(). There is no good reason to have this reference. There is no caller-callee relationship between threads. Not even a parent-child relationship like between the OS processed. One thread starts another and then may do whatever it pleases, including exiting. Having that reference would mean that if that thread exited, it could not be garbage collected until the other thread exits and gets garbage-collected too.

If you want, you can always add this manually by giving it as the argument to your thread constructor and remember it in the thread (subclass) object.
reply
    Bookmark Topic Watch Topic
  • New Topic