Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 137211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:04:14+00:00 2026-05-11T07:04:14+00:00

Essentially what I want is a BlockingQueue of size=1. I have a listener thread

  • 0

Essentially what I want is a BlockingQueue of size=1. I have a ‘listener’ thread that simply waits, blocking until an object is put into the queue, and then retrieves it–and a ‘producer’ thread that actually puts the object into the queue.

I can implement this with some synchronized blocks and a BlockingQueue implementation, but that seems like overkill. Is there a better, simpler way to do what I want?

Example interface:

public interface Wait<T> {   /**    * If 'put' has never been called on this object, then this method will    * block and wait until it has. Once 'put' has been called with some T, this    * method will return that T immediately.    */   public T get() throws InterruptedException;    /**    * @param object The object to return to callers of get(). If called more    * than once, will throw an {@link IllegalStateException}.    */   public void put(T object); } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:04:14+00:00Added an answer on May 11, 2026 at 7:04 am

    I found code for a class called ‘ObjectLatch’ here: http://forums.sun.com/thread.jspa?threadID=5321141

    package jfco.progs;  import java.util.concurrent.CountDownLatch;  /**  * <H1>A Blocking Object Latch</H1> This class implements a blocking object  * latch, that acts as a synchronizer between a producer of an object and it's  * consumer(s).  * <p>  * An object is set with <code>set()</code>only ONCE. Further attempts to set  * the object are just ignored.<br>  * <p>  * Consumers request the object with <code>get()</code>. If the object is not  * already set, consumers are blocked waiting until the object is available or <br>  * until an interrupt (InteruptedException) terminates the wait.  * <p>  * The latch can be tested for object availability with isAvailable(), which  * answers true if the object has already been set. <br>  */ public class ObjectLatch<R> {      /** 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).      * <p>      * 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;         }     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one table with 2 columns that i essentially want to split into
I want to implement a view in an iPhone application that is essentially like
I hava a CSV file that I want to treat as source code. Essentially
A mockup is below that probably explains better than words. Essentially, I want a
For example, I have 3 counters (which I essentially want to represent as truth
I have a form that I copied over from new.html.erb and put it in
I want to know if it is possible to make an event listener that
I essentially want to create a variable that would be executed every time. For
I am writing some JavaScript that what I essentially want to do is confirm
So, I essentially want to type in a letter into the text field and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.