Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 31 May 2011 12:39:26 -0500 Date: Tue, 31 May 2011 10:39:28 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Making one or more threads wait for another to produce a value or fail References: <4d858520-4121-45f2-a0cc-82e1a1cbd37d@f11g2000vbx.googlegroups.com> In-Reply-To: <4d858520-4121-45f2-a0cc-82e1a1cbd37d@f11g2000vbx.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <4KOdncWZ14NTunjQnZ2dnUVZ_hCdnZ2d@earthlink.com> Lines: 24 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 75.8.126.96 X-Trace: sv3-EwC36MdoP6kfuJJgmWI0SZw5VdRha+HJfScezBSAfZXstDaYQRlXK1vxRVkNnrwQyoqm1Cp3DFzOrI/!ZuW+xogWLGDEosfDsLRQ1fuPAr2LTc63sPNG04R0YiFrJvbMhGEsIBVFkseXGJycQyrI0BDHKWl7!N6jcA01+pBVanbYlFTHRn8xRdyvVdSq19Jz+KXITHbs= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2538 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:4805 On 5/31/2011 10:08 AM, Paul Cager wrote: > On May 31, 5:06 pm, Patricia Shanahan wrote: >> One way to do the synchronization would be a semaphore that is initially >> zero, but with a large number of permits added when Penelope calls a >> setVerdict method. The getVerdict method that the suitors call would >> wait to get a permit, record the verdict, and put the permit back so >> there is no possibility of running out of permits. > > Could you not subclass CountDownLatch and add a "verdict" property? I would definitely not subclass CountDownLatch. If I were to use it, the verdict delivery class would have a CountDownLatch reference as a field, along with fields representing the verdict. If you subclass CountDownLatch, or any other synchronization class, the choice of synchronization method becomes visible to the suitors and Penelope. They would be able to call all the CountDownLatch public methods directly, so desk checking the synchronization would involve checking all code with access to the subclass. That said, I think CountDownLatch is a better choice than my semaphore suggestion. Patricia