4 Replies Latest reply on Feb 17, 2010 4:41 PM by gavin.king

    Thread-safety

    romanb

      Hi,


      I'm starting out with Weld and have some questions regarding thread-safety of some (wider) scopes (session/conversation/...)


      I'm working through the example from chapter 3 of the reference documentation, where there is a @SessionScoped Login bean and a @RequestScoped Credentials bean. Apart from a question regarding scope-widening injection, which I'll ask in another thread, I've some questions about concurrency.


      As far as I know, @SessionScoped (or conversation/application-scoped) beans can be accessed concurrently, unless they're stateful/stateless EJB session beans, thus they must be thread-safe. If so, can the example in the documentation not be problematic? The @SessionScoped Login bean is not really thread-safe and the injected EntityManager, for example, is usually not thread-safe either.


      Similar concerns apply to the User instance provided by the producer method of the @SessionScoped Login bean, which might also be accessed concurrently when it is injected into other beans, unless I am missing something.


      In Guice, for example, it is highlighted that:



      Classes annotated @Singleton and @SessionScoped must be threadsafe. Everything that's injected into these classes must also be threadsafe.

      Is that different in Weld?


      In some other thread I found the following statement:



      Seam will serialize concurrent requests made to CONVERSATION scope or SESSION scoped beans

      Is that also the case for Weld? Even if it is, if its not part of the spec its not safe to rely on it anyway, is it?


      Thanks for clarifying!


      Roman