[concurrency-interest] Another CompletableFuture Question

Stanimir Simeonoff stanimir at riflexo.com
Wed Apr 30 10:28:01 EDT 2014


Hi Haim,

It's possible if you have the option to create the future yourself (for
example overriding AbstractExecutorService.newTaskFor) and/or submitting
subclasses of j.u.c.FutureTask (for Runnable) with overridden done() method
However if you just receive a plain Future object you can't do much but
poll either get() or isDone().

On a flip note: java.nio is pretty much what *nix IO is about, so I don't
have qualms there. The harder part coming with any higher level and
effective API is actually not copying the direct buffers.

Stanimir



On Wed, Apr 30, 2014 at 3:55 PM, √iktor Ҡlang <viktor.klang at gmail.com>wrote:

> Hi Haim,
>
>
> Your (only) options are:
>
> a) blocking (you already provided that solution)
> b) polling (have some thread have a set of Futures that it intermittently
> checks for isDone and then gets the value out)
>
> CompletableFuture > Future
>
>
> On Tue, Apr 29, 2014 at 10:02 PM, Haim Yadid <haim at performize-it.com>wrote:
>
>>
>> Hi,
>> Is the a good way to convert a future to a CompletableFuture ?
>> The only way I have found is to wrap the Future which causes an overhead
>> of another busy thread.
>>
>>     public static <V> CompletableFuture<V> convertFuture(Future<V>
>> future) {
>>         CompletableFuture<V> brighterFuture = supplyAsync(() -> {
>>             try {
>>                 return future.get();
>>             } catch (Exception e1) {
>>                 throw new RuntimeException(e1);
>>             }
>>         });
>>         return brighterFuture;
>>     }
>>
>>>
>>>
>>>
>>
>> --
>> Haim Yadid | Performization Expert
>> Performize-IT | t +972-54-7777132
>> www.performize-it.com
>>
>> _______________________________________________
>> Concurrency-interest mailing list
>> Concurrency-interest at cs.oswego.edu
>> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>>
>>
>
>
> --
> Cheers,
>>
> _______________________________________________
> 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/20140430/4a48ddfd/attachment-0001.html>


More information about the Concurrency-interest mailing list