• 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

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I want to do this task and i have a problem.
there is one array of constant length and many threads are trying to fill this array simultanously. Since this array is shared among these threads you need to apply synchronization in right region.

After the array is filled completely the average of the array elements should be calculated and printed in the console.

this is my question:
1)filling array is my region synchronization .i don't underestand , why i should use join method when i have synchronization .because synchronization means one thread should do it's work and when it's work is finished another
thread can come.am i true?

thanks
zohreh
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

"join()" lets you wait for a Thread to exit completely. Imagine a main program that starts ten worker threads, where each one has a job to do. When all ten are done, the main program wants to print "All done!" and then exit. The main program could call join() on all ten threads, in a loop. When all ten join() calls have returned, the main program knows all the work is done, so it can print a message.

But you are right -- most uses of synchronization do not involve calling join(); join is not really related to synchronization at all.
 
Ranch Hand
Posts: 291
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like a homework assignment to me.

Without knowing why you want to use join() and what the instructor is looking for, it's difficult to know how to respond.
 
Why am I so drawn to cherry pie? I can't seem to stop. Save me tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic