Forums Register Login

how it works---join(),thread class.

+Pie Number of slices to send: Send
hello every one!
can anyone, please tell me how this join() method of the tread class works, also when it is called with parameters.
thanks.
+Pie Number of slices to send: Send
AoA Annie !
Read ur call, and wanted to tell u what i found about join() method. so here it is. Do tell me is it helpful or not ?

tabinda says:
okay have u studied join() method too ?
Inam says:
ya
tabinda says:
tell me what does it do ? and why we use it ?
Inam says:
when we want a thread not to stop Before its Child thread
then we use this method
4 example
if there r child threads for main
Main should not be terminated
before its child threads
Inam says:
then we use the syntax
obj.join()
Inam says:
obj is the child thread for main
tabinda says:
yes and it will not let the main thread finish before obj right ?
Inam says:
ya absolutely
Inam says:
this is it all
tabinda says:
accha can we say that "by using join() method we don't have to put the main thread to call sleep() method to finish last after its child threads terminate becoz join() method takes care of that "
tabinda says:
tell me is the above statement correct in ur opinion ?
Inam says:
absolute abt join().
Inam says:
its right 2 say like this
tabinda says:
good
Inam says:
n its a better way than sleep()
tabinda says:
now tell me one more thing regarding join(long millis)
tabinda says:
what does it do ?
tabinda says:
does it keeps the main thread from finishing for only the particular amount of time specified in the block ?
tabinda says:
i mean in the parameter block of this method call
Inam says:
ya
Inam says:
ya it stops main thread from termination for the time specified as argument
tabinda says:
but then don't u think its better to use join() becoz it never lets the main thread die before its child thread
Inam says:
ya u r right its better 2 use join() rather than join(long mili sec)
--------------------------------------------------

Now another reference from a java site :

join() method. This blocks the calling thread until the thread whose join() method is called is terminated. And my dear friend u must have guessed that the calling thread is none other than main thread itself. So main method is blocked until child thread terminates.
join([timeout])
Wait until the thread terminates. This blocks the calling thread until the thread whose join() method is called terminates - either normally or through an unhandled exception - or until the optional timeout occurs.
* When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof).
* A thread cannot join itself because this would cause a deadlock.
* It is an error to attempt to join() a thread before it has been started.

Hope that it will help u out. take care
Allah Hafiz !
tabinda
+Pie Number of slices to send: Send
HERE IS YOUR ANSWER:
Q. What does the Thread.join() method do? Can you give an example?
[ March 24, 2002: Message edited by: Roseanne Zhang ]
+Pie Number of slices to send: Send
Roseanne's example, unfortunately, does demonstrate the semantics of join() but not what it's good for, as the main thread merely waits until the job thread has finished. You could just as well do all the work in the main thread.
Job threads and join() are especially powerful when there two or more I/O-bound things have to happen which can be done in parallel. You can then "fork" the path of execution and do everything at the same time. You use Thread.join to join the teeth of the fork back together again at the end (to stretch the analogy a bit ).Does that help?
- Peter
PS. Thanks for the code Roseanne
She said she got a brazillian. I think owning people is wrong. That is how I learned ... tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2388 times.
Similar Threads
Finding a prime number
join() method of class Thread
is it a DeadLock Condition?
Thread class join() method
Threads: join() and volatile instance variables
concurrency
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 07:27:30.