• 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
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

threads.....

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all.......
if i call the join() method in the run() method of ne thread like the one in following code :

public void run()
{
join(1000);// will halt the execution of this thread for 1 sec

join();// will stop this thread permanantly
}
ok, so i think if v call join() in run() method of ne thread it act same as sleep(long mills) ( or sleep(long infinite) as in the 2nd case ).
is my this understanding is correct?
plz correct me if i m wrong.
thx in advance
.........Ajit
 
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope... Join() method waits for a thread to die where as sleep just halts the thread temporarily..
Here is the definition from the API docs:
SLEEP -> Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds. The thread does not lose ownership of any monitors.
JOIN -> Waits for this thread to die.

Originally posted by Ajit B:
hi all.......
if i call the join() method in the run() method of ne thread like the one in following code :

public void run()
{
join(1000);// will halt the execution of this thread for 1 sec

join();// will stop this thread permanantly
}
ok, so i think if v call join() in run() method of ne thread it act same as sleep(long mills) ( or sleep(long infinite) as in the 2nd case ).
is my this understanding is correct?
plz correct me if i m wrong.
thx in advance
.........Ajit


 
Ajit B
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Roopa.....
thx for replying but i think u dint get my question?

JOIN -> Waits for this thread to die.


(its just join() not t1.join().)
i want to ask what happens when u call join on the currentThread?
in the above code i m calling join () on the currentThread. so the thread which called join() waits for the calling thread (same thread which called join() )to finish.

i think if v call join() in run() method of ne thread it acts same as sleep(long mills) ( or sleep(long infinite) as in the 2nd case ).


so isn't it that join() behaves as sleep() when called inside run()???
waiting for reply,
Ajit
 
reply
    Bookmark Topic Watch Topic
  • New Topic