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.