• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

join method functionality

 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am confused about the functionality of the join method in threads.
From what I understand, calling join on a thread t from methodA() will make the methodA() sleep until the thread t's execution is done.
If this is indeed the case, then the same functionality can be (more or less) implemented by calling the sleep method directly on the method whose execution we want to temporarily suspend.
I'd appreciate any feedback at the earliest.
Thanks,
Saket
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Saket
A sleep() method would cause a thread to sleep() for a specified amount of time. There is no sleep() method that doesn't takes any argument. So you will have to specify the timeout. Now in case you wish get the same functionality as of the the join() method you will have to specify the time atleast equal to or greater than the time of the other thread which you want should complete. You can not be sure how long it takes each time and on each platform. Hence a join() method seems a better option. One more thing

From what I understand, calling join on a thread t from methodA() will make the methodA() sleep until the thread t's execution is done.


Calling join on a thread t from methodA() will not make the methodA() sleep but will make the thread executing methodA() sleep until the thread t's execution is done.

then the same functionality can be (more or less) implemented by calling the sleep method directly on the method whose execution we want to temporarily suspend.


Similarly sleep is a Thread class method a will make a Thread( or its subclass) object to goto sleep. So the above sentenced would be better worded as "then the same functionality can be (more or less) implemented by calling the sleep method directly on the Thread class object's(or its subclass) whose execution we want to temporarily suspend."
[ May 24, 2003: Message edited by: Anupam Sinha ]
 
Saket Barve
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anupam,
The mistakes you noted in my words are suttle, yet very significant.
Thanks for your feedback, which has really helped clarify my doubt.
Saket
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
read this somewhere which is concerned and makes sence.
target.join IS SAME AS
while(target.isAlive()) sleep(t);
where t is the minimal time we can specify. so using sleep() can approach the usefulness of join() but does not fully replace it.
 
reply
    Bookmark Topic Watch Topic
  • New Topic