我正在使用 Weld 来观察事件。我认为有一种方法可以指定观察者是否是异步的,但我没有找到该注释或文档。
观察者可以是异步的吗?如果可以,我需要做什么才能做到这一点?
我正在使用 Weld 来观察事件。我认为有一种方法可以指定观察者是否是异步的,但我没有找到该注释或文档。
观察者可以是异步的吗?如果可以,我需要做什么才能做到这一点?
对此有一个开放的请求:CDI-31:异步事件。
根据您的要求,您可以按照评论中的说明设置不同的事务观察者:如果您使用 AFTER_COMPLETION 或 AFTER_SUCCESS,它在您的应用程序中应该看起来像异步执行。但是,在解决框架之前,我刚刚找到了一个使用JMS 在 CDI 中进行异步执行的示例。
看看Piotr Nowicki博客上的帖子http://piotrnowicki.com/2013/05/asynchronous-cdi-events/
他描述了几种实现 CDI 事件异步行为的方法。
If you guys want to see this happen, you'll need to head over the the link provided in Kariem's answer and voice your opinion. It seems the expert group is unwilling to consider adding async events because they consider it bloating the spec.
Honestly, Guice manages to offer this feature, and it remains lightweight, so I find the argument against this little counter-intuitive. Nevertheless, if you want to see this feature, head to the link, voice your opinion.
-Jonathan