[concurrency-interest] some MapMaker design decisions

Jim Newsham jnewsham at referentia.com
Tue May 11 22:19:04 EDT 2010


On 5/11/2010 8:52 AM, Charles Fry wrote:
> b) If eviction notifications are made using callbacks, where should
> the callback be executed? We could execute them on user threads when
> they make other calls on MapMaker maps, but that implies that
> exceptions and blocking within callbacks could then impact threads
> performing other operations on the map. The other obvious alternative
> would be to require users to provide an ExecutorService for executing
> callbacks, but that feels a bit overkill when all you really want is
> an eviction notification.
>    

We've occasionally done "both".  In our application, we often have the 
desire for the listener to be able to specify how events should be 
delivered to it (primarily, which thread).  In such cases we extend the 
conventional Java listener approach to also provide an optional Executor 
(not ExecutorService; note that Executor interface is much simpler and 
less burdensome to implement) parameter as follows:

addFooListener(FooListener listener);

addFooListener(FooListener listener, Executor executor);

We have a few executors that we like to use regularly, including a 
SerialExecutor, EdtExecutor, etc.

Jim


More information about the Concurrency-interest mailing list