[concurrency-interest] Another CompletableFuture Question

√iktor Ҡlang viktor.klang at gmail.com
Wed Apr 30 09:10:09 EDT 2014


Hi Haim,

from a quick glance I'd assume for compatibility reasons.
The classes you mention are abstract and as such there are implementations
out there that return Future, so you couldn't retrofit the methods to
return a more specific type (CompletableFuture).

And I also assume that there was neither time nor a desire to duplicate all
the API methods (since Java doesn't fare well with return type overloading).

A Future Java could/should in my opinion move away from the current
(n)io(1/2) libraries and offer IO APIs built to use non-blocking,
asynchronous streams with built in backpressure, as being worked on by the
Reactive Streams SIG—I'd even go so far as to say that it is java.io done
right.

The above is of course only my personal opinions as I have no insight into
the Java SDK roadmap etc.


On Wed, Apr 30, 2014 at 3:00 PM, Haim Yadid <haim at performize-it.com> wrote:

> Thanks Viktor
> Do you ( or anyone else ) know why
>
>    - AsynchronousFileChannel
>    - AsynchronousServerSocketChannel
>    - AsynchronousSocketChannel
>
> where not converted to support CompletableFutures as well?
>
>
> 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,
>>>>
>
>
>
> --
> Haim Yadid | Performization Expert
> Performize-IT | t +972-54-7777132
> www.performize-it.com
>



-- 
Cheers,
√
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20140430/e6243ba5/attachment.html>


More information about the Concurrency-interest mailing list