Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found code for a class called "ObjectLatch" here: <a href="http://forums.sun.com/thread.jspa?threadID=5321141" rel="nofollow noreferrer">http://forums.sun.com/thread.jspa?threadID=5321141</a></p> <pre><code>package jfco.progs; import java.util.concurrent.CountDownLatch; /** * &lt;H1&gt;A Blocking Object Latch&lt;/H1&gt; This class implements a blocking object * latch, that acts as a synchronizer between a producer of an object and it's * consumer(s). * &lt;p&gt; * An object is set with &lt;code&gt;set()&lt;/code&gt;only ONCE. Further attempts to set * the object are just ignored.&lt;br&gt; * &lt;p&gt; * Consumers request the object with &lt;code&gt;get()&lt;/code&gt;. If the object is not * already set, consumers are blocked waiting until the object is available or &lt;br&gt; * until an interrupt (InteruptedException) terminates the wait. * &lt;p&gt; * The latch can be tested for object availability with isAvailable(), which * answers true if the object has already been set. &lt;br&gt; */ public class ObjectLatch&lt;R&gt; { /** The object. */ private R object = null; /** The latch counter created and set to 1. */ private final CountDownLatch latch = new CountDownLatch(1); /** * Checks if the object is already available (has been already set). * * @return true, if the object is already available (has been already set) */ public boolean isAvailable() { return latch.getCount() == 0; } /** * Sets the object if it is not already set. Otherwise ignore this request. * * @param object * the object */ public synchronized void set(R object) { if (!isAvailable()) { this.object = object; latch.countDown(); } } /** * Get the object if it is already available (has already been set). * &lt;p&gt; * If it is not available, wait until it is or until an interrupt * (InterruptedException) terminates the wait. * * @return the object if it is already available (has already been set) * * @throws InterruptedException */ public R get() throws InterruptedException { latch.await(); synchronized (this) { return object; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload