[concurrency-interest] When do you use wait/notify?

Ian Griffiths ian.griffiths@yellow-b.com
Sun, 25 Jan 2004 09:15:33 +0100


I am new to this list and should like to apologize if something has 
escaped my attention.

I still use wait notify to handle a very simple Future implementation.

In my application, I have a number of objects I may be asked to provide 
and have a very low priority thread that will instantiate them all over 
time.

However many of the objects may also be produced as by-products of 
other tasks that get them from other, parallel, processes or that 
create them in response to an urgent request. thus sparing my basic 
thread the tiresome job of re-calculating them from scratch.

To do this I use a very implementation of a Future:

package jet.util.concurrency;

/**
 * A Future is an object that encapsulates a value that may 
 * only appear at a later date.
 */
public interface Future {

	/**
	 * Method getValue.
	 * @return Object the value of the Future
	 * @throws InterruptedException If the wait is interrupted
	 */
    public Object getValue() throws InterruptedException;
	/**
	 * Method isSet Says whether a value has been set.
	 * @return boolean true if a value has been set.
	 */
    public boolean isSet();
	/**
	 * Method setValue.Set the value for this future
	 * @param value The value to be set.
	 */
    public void setValue(Object value);
}

The important point is that the Future is not linked to any specific 
task, as I do not know how it will be obtained when I create the Future.

Best Regards.