Behavior of CDI fireAsync when using CompletionStage.whenCompleteAsync
by John Ament
Run into an interesting issue. Not sure if its an RI problem, or something else. Actually not even sure if its a problem just surprised me.
I have two very simple main methods here:
try(SeContainer container = SeContainerInitializer.newInstance()
.addPackages(Pojo.class)
.disableDiscovery()
.initialize()) {
Event<Object> event = container.getBeanManager().getEvent();
FixedThreadPoolExecutorServices executorServices = new FixedThreadPoolExecutorServices(2);
CompletionStage<Pojo> completionStage = event.fireAsync(new Pojo("this is asynchronous"), NotificationOptions.ofExecutor(executorServices.getTaskExecutor()));
completionStage.whenCompleteAsync((pojo, throwable) -> event.fire(new Pojo(pojo.showName() + ", and now this is synchronous")));
Thread.sleep(500L);
}
public static void main(String...args) throws Exception{
try(SeContainer container = SeContainerInitializer.newInstance()
.addPackages(Pojo.class)
.disableDiscovery()
.initialize()) {
Event<Object> event = container.getBeanManager().getEvent();
CompletionStage<Pojo> completionStage = event.fireAsync(new Pojo("this is asynchronous"));
completionStage.whenCompleteAsync((pojo, throwable) -> event.fire(new Pojo(pojo.showName() + ", and now this is synchronous")));
Thread.sleep(500L);
}
}
In the first, I'm using a custom executor (a 2 thread pool executor) and the latter just using the default unspecified version, which weld seems to use a fork-join pool. In both of these examples, I use the whenCompleteAsync method. in the first method, I always see the fired event being handled in a different thread than what handled the first event. In the second method, I always see the fired events both being handled in the same thread. Is that just the behavior of fork-join? Or something special happening?
John
________________________________
NOTICE: This e-mail message and any attachments may contain confidential, proprietary, and/or privileged information which should be treated accordingly. If you are not the intended recipient, please notify the sender immediately by return e-mail, delete this message, and destroy all physical and electronic copies. Thank you.
7 years, 9 months
[JBoss JIRA] (CDI-695) Allow stereotypes to include priority annotations
by Antoine Sabot-Durand (JIRA)
[ https://issues.jboss.org/browse/CDI-695?page=com.atlassian.jira.plugin.sy... ]
Antoine Sabot-Durand commented on CDI-695:
------------------------------------------
IMO, I think it would bring more confusion than useful:
* A Stereotype is usually created to be used on many elements. What would be the interest to apply same priority in different places?
* {{@Priority}} is used and activate Interceptors and Alternatives and not having this info directly on the element can be source of confusion IMO.
Could you give a use case where it could be interesting to have this?
> Allow stereotypes to include priority annotations
> -------------------------------------------------
>
> Key: CDI-695
> URL: https://issues.jboss.org/browse/CDI-695
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Reporter: John Ament
>
> Stereotypes can include things like Alternative. However, there is no mention as to whether or not Priority can be included in the stereotype definition. I feel it would be useful to be included.
--
This message was sent by Atlassian JIRA
(v7.2.3#72005)
7 years, 9 months
[JBoss JIRA] (CDI-695) Allow stereotypes to include priority annotations
by John Ament (JIRA)
John Ament created CDI-695:
------------------------------
Summary: Allow stereotypes to include priority annotations
Key: CDI-695
URL: https://issues.jboss.org/browse/CDI-695
Project: CDI Specification Issues
Issue Type: Feature Request
Reporter: John Ament
Stereotypes can include things like Alternative. However, there is no mention as to whether or not Priority can be included in the stereotype definition. I feel it would be useful to be included.
--
This message was sent by Atlassian JIRA
(v7.2.3#72005)
7 years, 9 months