[concurrency-interest] ImmediateFuture

Joe Kearney Joe.Kearney at morganstanley.com
Wed Jun 17 12:21:09 EDT 2009


If you want to avoid a new top-level type you could always create an
anonymous ConstantSimpleImmediateFuturePast (or whatever :) ) implementation
in the futureFor method, rather that than add the runtime cost of the
runnable and AQS sync overhead in the FutureTask.

2009/6/17 Jim Andreou <jim.andreou at gmail.com>

> One could use something like this, to avoid introducing a new type:
>
> private static final Runnable emptyRunnable = new Runnable() { public void
> run() { } };
> public static <T> Future<T> futureFor(T value) {
>     return new FutureTask<T>(emptyRunnable, value);
> }
>
> 2009/6/17 Joe Kearney <Joe.Kearney at morganstanley.com>
>
> I had to write one of these, I called it ConstantFuture. Fairly trivial
>> implementation, but would be nice to have on hand.
>>
>> 2009/6/17 Mark Thornton <mthornton at optrak.co.uk>
>>
>>> For test purposes I created an ImmediateFuture class which implements
>>> Future but where the value already exists. Am I the only person to have
>>> found the need to do this or should something like it be considered for more
>>> general use?
>>>
>>>
>>> Mark Thornton
>>>
>>> _______________________________________________
>>> Concurrency-interest mailing list
>>> Concurrency-interest at cs.oswego.edu
>>> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>>>
>>
>>
>> _______________________________________________
>> Concurrency-interest mailing list
>> Concurrency-interest at cs.oswego.edu
>> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20090617/c45930f5/attachment.html>


More information about the Concurrency-interest mailing list