[concurrency-interest] Waiting for object value to be available.

Shaffer, Darron Darron_Shaffer at stercomm.com
Tue Aug 23 14:04:12 EDT 2005


The old WaitableReference class would do this nicely.  Unfortunately, it
didn't make it into Java 5.

By the way, why didn't this group of classes end up in Java 5?


-----Original Message-----
From: concurrency-interest-bounces at cs.oswego.edu
[mailto:concurrency-interest-bounces at cs.oswego.edu] On Behalf Of Peter
Veentjer - Anchor Men
Sent: Tuesday, August 23, 2005 12:00 PM
To: Doug Lea; concurrency-interest at altair.cs.oswego.edu
Subject: RE: [concurrency-interest] Waiting for object value to be
available.

I think the most common approach to this sort of problem is to use
an Observer or Listener design. (My CPJ book includes a description
in section 3.5.2). This might be overkill here if you don't want or
need to otherwise maintain observers in lists and multicast to them
change notifications.
------------------------
It is very important that the threads that want to read the value, are 
going to sleep untill a value is available. I think it is more complex 
to create this behaviour by using a observer/observable than a
small concurrency stone.
 
And you could see the wait/notify functionality of java as a
observer/observable. The observers (threads) are waiting in a list
(every java object
can have a collection of threads waiting to be notified) and the event 
would be the signal. So I don`t see the need to create java objects for 
something that already is in the core of Java.
 
Let me explain where this NullWaiter is going to be part of. I need 
something that can be compared to a ThreadPoolExecutor. But I don`t
want to execute a single job, but I want to execute a job by all
threads in that structure repeatedly (untill the task is set to null). I
have
called this structure the Repeater. The NullWaiter is going to be
part of the Repeater and contains the task all threads are waiting for.
If no task is available, all threads wait. But if a task is available,
they will keep repeating it..over.. and over.. and over.
 
Why do I need such a strange beast? It is going to be part
of a channels project I`m writing. One of the usages is that a
Repeater is going to 'suck' messages out of a channel.
 
example:
 
 public static void main(String[] args){
  Channel<FetchRequest> requestChannel = new
StdBufferedChannel<FetchRequest>(500);
  Channel<FetchResult> resultChannel = new
StdBufferedChannel<FetchResult>(50);
  
  RepeaterService fetchRepeater = new StdRepeaterService(5);//5 threads
  fetchRepeater.start();
  Fetcher fetcher = new
Fetcher(requestChannel,resultChannel,fetchRepeater);
  
  RepeaterService analyzeRepeater = new StdRepeaterService(1);//1 thread
  analyzeRepeater.start();
  Analyzer analyzer = new
Analyzer(resultChannel,requestChannel,analyzerExecutor);
  
  try {
       requestChannel.put(new FetchRequest(new
URL("http://dmoz.org/")));
  } catch (InterruptedException e) {
   e.printStackTrace();
  } catch (MalformedURLException e) {
   e.printStackTrace();
  }
 }
 
 
 
 



_______________________________________________
Concurrency-interest mailing list
Concurrency-interest at altair.cs.oswego.edu
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest



More information about the Concurrency-interest mailing list