@Observes in sessionscoped bean?

社会主义新天地 提交于 2019-12-04 15:11:12

"The correct instance" is a slightly misleading wording.

What happens is this:

  1. The SessionService is invoked (probably triggered by a web request).
  2. If it fires its LoggedInEvent, all registered observers are called in a synchronous way (meaning that SessionService will not terminate before all observers terminate).
  3. Each bean containing a (non-static) observer method will be instantiated (provided that the bean scope is active - which it usually is in a standard web environment(*)). This will be the case for your SessionBean. If - and only if - SessionBean has already been instantiated in your active session (there's certainly only one session active regarding the web request), then this instance will of course be used.

More details in the spec.

So, to answer you question:

Yes, the correct instance will be called. Why? Because it's the responsibility of the container to make sure that only one SessionBean-instance is associated with the active session scope.

(*): If an invocation is for example triggered by a remote ejb call, you can neither assume an active session nor an active conversation...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!