[cdi-dev] CompletableFuture vs. CompletionStage

Reza Rahman reza_rahman at lycos.com
Tue Mar 8 07:19:18 EST 2016


FYI I am running a survey on this issue: https://twitter.com/reza_rahman/status/707035213717774336. If you really are open to feedback, I suggest keeping an eye there. When it is done, it is possible I will blog about this if it is clear this is a going to be a problem. In the least people will hopefully have that as a resource when they are confused.

The reality is that everyone has limited time. I can provide feedback when I can provide feedback for any number of personal reasons including whether my employer allows it. It is ultimately up to you to consider it fairly and objectively at all times. If you are failing to do that for any reason before the spec is final it is rather unfortunate for anyone relying on the spec.

In the end the beauty of all of this is that none of this impacts my livelihood immediately any more. I am just another developer again now. In the end I get to walk over to the Spring camp like everyone else. And thank goodness for that freedom.

Kindly do not assume I will be spending a lot of time providing you feedback going forward. That was unlikely at all times given my time constraints. You should assume the same for most developers out there. When you get feedback from us, you should consider it in that light.

> On Mar 8, 2016, at 5:37 AM, Antoine Sabot-Durand <antoine at sabot-durand.net> wrote:
> 
> Answer inline
> 
>> Le mar. 8 mars 2016 à 03:15, Reza Rahman <reza_rahman at lycos.com> a écrit :
>> I have forwarded this issue to the Java EE platform EG for review. My inclination now is to simply leave this alone with a final earnest request to kindly think carefully about this before finalizing and getting this into the real world. Please keep in mind that the average developer is not that skilled and looks to resources on the web routinely for answers. All those resources are going to immediately point to CompletableFuture, not some obscure superclass.
> 
> CS is not an obscure superclass it's an interface and all methods in CF returns it, so it's impossible  to learn CF and ignore CS existence.
> Concurrency is not an easy feature to use, people that think they can cut and paste code from stack overflow without digging in the doc will hit a wall very soon.
> We decided to return a CS to allow advanced user to use it to build async pipeline from here. I guess that the majority of beginners will ignore this returned object (as they would have do it if it had been a CF).
>  
>> 
>> All I am trying to do is help design an API that is not going to immediately become difficult for the average end developer to understand and use. It's rather unfortunate that I am already feeling fed up in that simple effort to provide feedback.
> 
> Reza, feedback is always welcome. But if you don't do it in time you should expect some resistance from the EG who worked a long time (and in an open way) to take these decision. So you need more arguments than "user don't know CS" to make us switch from an interface to an impl, that is not suited for Java EE.
> Feedback on possible technical issues are welcome.  
>  
>> 
>> Anyway I am now basically done with this. Unfortunately I have far more urgent matters for Java EE 7 and Java EE 8 to deal with. If I have time I'll look at some more of the CDI 2 work and provide feedback if I can manage time.
> 
> Again it's welcome. We are about to discuss a programmatic APi for SE boot. Your input will be precious here.
>  
>> 
>>> On Mar 7, 2016, at 2:53 PM, Reza Rahman <reza_rahman at lycos.com> wrote:
>>> Argue
>>> Yes, this can be done with a CompletableFuture that has already been constructed - just take a look at the API.
>>> 
>>> As far as not adding it to CDI, I can see either way. What was the original motivation for adding CompletableFutures?
>>> 
>>> Also, it's a good idea to run this by the platform expert group. I know at least JAX-RS is planning to use CompletableFutures for their client API.
>>> 
>>>> On Mar 7, 2016, at 2:39 PM, Romain Manni-Bucau <rmannibucau at gmail.com> wrote:
>>>> 
>>>> 
>>>> 2016-03-07 20:35 GMT+01:00 Reza Rahman <reza_rahman at lycos.com>:
>>>>> Talking with a colleague about this he reminded me of an important fact I almost forgot. The CompletableFuture API can actually be used with custom executors. That means users concerned about managed threads in a Java EE environment can use it with existing EE 7 concurrency executors.
>>>>> 
>>>>> Basically this means CompletableFutures are already pretty Java EE ready.
>>>>> 
>>>>> If this is the main cited reason for using CompletionStage, is it really that valid of an argument to justify yet another custom subclass specific only to CDI instead of what's likely to be far more familiar and expected?
>>>>> 
>>>> 
>>>> Did he mention it is true for *created* comlpetion future which is not the case for async events? But this is a good point to not add anything to CDI: the feature is a one liner *already*.
>>>>  
>>>>>> On Mar 7, 2016, at 8:11 AM, Reza Rahman <reza_rahman at lycos.com> wrote:
>>>>>> 
>>>>>> I think this is a very bad idea. It's better not to use either API and wait to sort out how CompletableFuture can be used in EE consistently. Because of backwards compatibility rules, it is better to have no API than a bad API.
>>>>>> 
>>>>>>> On Mar 7, 2016, at 3:45 AM, Romain Manni-Bucau <rmannibucau at gmail.com> wrote:
>>>>>>> 
>>>>>>> 2016-03-07 9:07 GMT+01:00 Martin Kouba <mkouba at redhat.com>:
>>>>>>>> 
>>>>>>>> Dne 7.3.2016 v 09:03 Romain Manni-Bucau napsal(a):
>>>>>>>>> 
>>>>>>>>> Le 7 mars 2016 08:35, "Martin Kouba" <mkouba at redhat.com
>>>>>>>>> <mailto:mkouba at redhat.com>> a écrit :
>>>>>>>>>  >
>>>>>>>>>  > Dne 6.3.2016 v 15:39 Romain Manni-Bucau napsal(a):
>>>>>>>>>  >
>>>>>>>>>  >> Hi guys,
>>>>>>>>>  >>
>>>>>>>>>  >> as a user having a ComlpetionStage makes me loose some JDK utilities,
>>>>>>>>>  >> can we move back to CompletionFuture?
>>>>>>>>>  >>
>>>>>>>>>  >> It would allow for instance:
>>>>>>>>>  >>
>>>>>>>>>  >> // doesn't work with CompletionStage
>>>>>>>>>  >> CompletionFuture.allOf(event1.fireAsync(...), event2.fireAsync(...))
>>>>>>>>>  >>        .then(...)
>>>>>>>>>  >
>>>>>>>>>  >
>>>>>>>>>  > Well, this should work if the underlying CompletionStage impl
>>>>>>>>> supports toCompletableFuture(), i.e. in Weld 3:
>>>>>>>>>  >
>>>>>>>>> 
>>>>>>>>> Yes but it is not natural to convert it IMO = we can do better
>>>>>>>>> 
>>>>>>>>>  > CompletableFuture.allOf(event1.fireAsync(...).toCompletableFuture(),
>>>>>>>>> event2.fireAsync(...).toCompletableFuture())
>>>>>>>>>  >
>>>>>>>>>  > AFAIK the default async execution facility of CompletableFuture is
>>>>>>>>> ForkJoinPool.commonPool() which is not a good fit for Java EE. Using the
>>>>>>>>> CompletionStage interface allows us to wrap the async calls without the
>>>>>>>>> specified executor (e.g. CompletionStage.thenApplyAsync(Function<? super
>>>>>>>>> T, ? extends U>)) and supply a default one provided by the impl.
>>>>>>>>>  >
>>>>>>>>> 
>>>>>>>>> Should use the pool in which the evznt is fired then "then step" is
>>>>>>>>> synchronous is my sample so all is decided at fire time
>>>>>>>> 
>>>>>>>> I don't talk about your particular example - I understand that it's not using async exec (although the "then()" method does not exist).
>>>>>>>> 
>>>>>>> 
>>>>>>> was supposed to represent the different flavours (thenRun, thenCompose, ...) ;).
>>>>>>> 
>>>>>>> That said I agree on the state switching the pool is better but with these 2 notes:
>>>>>>> 
>>>>>>> - could be better to hide these poorly designed methods then -> don't use CompletionXXX but a CDI API with a bridge to CompletionX to let the user go back on SE tools
>>>>>>> - we still don't have a *standard* config for the pool(s) underlying CDI features so it sounds as poor as SE solution IMO (at least a core/max/ttl config in beans.xml)
>>>>>>>  
>>>>>>>>> 
>>>>>>>>>  >
>>>>>>>>>  >>
>>>>>>>>>  >> Romain Manni-Bucau
>>>>>>>>>  >> @rmannibucau <https://twitter.com/rmannibucau> | Blog
>>>>>>>>>  >> <http://rmannibucau.wordpress.com> | Github
>>>>>>>>>  >> <https://github.com/rmannibucau> | LinkedIn
>>>>>>>>>  >> <https://www.linkedin.com/in/rmannibucau> | Tomitriber
>>>>>>>>>  >> <http://www.tomitribe.com>
>>>>>>>>>  >>
>>>>>>>>>  >>
>>>>>>>>>  >>
>>>>>>>>>  >> _______________________________________________
>>>>>>>>>  >> cdi-dev mailing list
>>>>>>>>>  >> cdi-dev at lists.jboss.org <mailto:cdi-dev at lists.jboss.org>
>>>>>>>>>  >> https://lists.jboss.org/mailman/listinfo/cdi-dev
>>>>>>>>>  >>
>>>>>>>>>  >> Note that for all code provided on this list, the provider licenses
>>>>>>>>> the code under the Apache License, Version 2
>>>>>>>>> (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas
>>>>>>>>> provided on this list, the provider waives all patent and other
>>>>>>>>> intellectual property rights inherent in such information.
>>>>>>>>>  >>
>>>>>>>>>  >
>>>>>>>>>  > --
>>>>>>>>>  > Martin Kouba
>>>>>>>>>  > Software Engineer
>>>>>>>>>  > Red Hat, Czech Republic
>>>>>>>>> 
>>>>>>>> 
>>>>>>>> -- 
>>>>>>>> Martin Kouba
>>>>>>>> Software Engineer
>>>>>>>> Red Hat, Czech Republic
>>>>>>> 
>>>>>>> _______________________________________________
>>>>>>> cdi-dev mailing list
>>>>>>> cdi-dev at lists.jboss.org
>>>>>>> https://lists.jboss.org/mailman/listinfo/cdi-dev
>>>>>>> 
>>>>>>> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
>>>>> 
>>>>> _______________________________________________
>>>>> cdi-dev mailing list
>>>>> cdi-dev at lists.jboss.org
>>>>> https://lists.jboss.org/mailman/listinfo/cdi-dev
>>>>> 
>>>>> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
>>>> 
>> _______________________________________________
>> cdi-dev mailing list
>> cdi-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/cdi-dev
>> 
>> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/cdi-dev/attachments/20160308/58d79f78/attachment-0001.html 


More information about the cdi-dev mailing list