[concurrency-interest] Basic question on making a thread waiting for 2 mailboxes...

Peter Veentjer alarmnummer at gmail.com
Mon Apr 23 11:29:16 EDT 2007


Hi Fred,

the functionality you are looking for looks a lot like the
http://java.sun.com/j2se/1.4.2/docs/api/java/nio/channels/Selector.html
in non blocking io (nio). Each mailbox can be seen as an
http://java.sun.com/j2se/1.4.2/docs/api/java/nio/channels/SelectableChannel.html
and multiple channels can be handled by a single thread.

But as far as I know there is no synchronization structure in j.u.c
that can provide the same functionality for arbitrary event sources.

On 4/23/07, Fred Janon <fjanon at gmail.com> wrote:
> Hi,
>
> I used to write real time apps using RSX11M+ (and VMS) that had mailboxes
> and events. There was a "wait for OR(events)". The task would wait for any
> event specified in the OR. Then I would associate an event with a mailbox,
> do that for another mailbox and when a message would arrive in one of the 2
> mailboxes, the task would awake. I am trying to do that in Java with
> threads.
>
> I have been reading "Java Threads",  "JCIP", "Java in a Nutshell" and I
> could think about a couple of classes I could use but I would appreciate
> some design advice... Or if there is an existing library that does that
> already does that, I would appreciate a reference, I did some research and
> did not find anything interesting.
>
> Basically I need 1 public mailbox and 1 private mailbox for a thread. The
> thread would be blocked until a message arrives in one of the mailboxes. The
> mailboxes must have multiple slots. I was thinking about using
> LinkedBlockingQueues as mailboxes since I don't want to block the sender (or
> avoid it) but I am a bit stuck on making the thread wait for a message in
> either queues.
>
> The next step would be to have a ThreadPool for the tasks, sharing a common
> public mailbox to process the messages and each have a private mailbox for
> system management messages. I guess switching to a single thread to a
> ThreadPool would be relatively easy?
>
> Thanks in advance.
>
> Fred
>
> _______________________________________________
> 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