-
1. Re: Seam's MailSession is not Thread safe
pbrewer_uk Oct 30, 2009 4:48 PM (in response to pbrewer_uk)Following up, this is actually a more generic issue (have observed this occurring on the FaceletsCompiler component and potentially others), effecting Application scoped components that use @Create.
Consider the following case:
@Name("myWrapper") @Scope(APPLICATION) public class MyWrapper { private Object wrappedObject ; @Create public void setupWrappedObject() { // code to setup the wrappedObject ... this.wrappedObject = aValue ; } @Unwrap public Object getWrappedObject() { return this.wrappedObject ; } }
And then consider how Seam creates the instance when it is referenced (extract from Component.java)...
public Object newInstance() { if (log.isTraceEnabled()) { log.trace("instantiating Seam component: " + name); } Object instance; try{ instance = instantiate(); if (getScope()!=STATELESS) { //put it in the context _before_ calling postconstuct or create getScope().getContext().set(name, instance); } postConstruct(instance); if (getScope()!=STATELESS) { callCreateMethod(instance); if (Events.exists()) { Events.instance().raiseEvent("org.jboss.seam.postCreate." + name, instance); } } } catch (Exception e) { if (getScope()!=STATELESS) { getScope().getContext().remove(name); } throw new InstantiationException("Could not instantiate Seam component: " + name, e); } return instance; }
In a multi-threaded environment, setting the variable in the context prior to running @Create means that other components may access the @Unwrap method prior to the @Create method completing. From the seam code comment
put it in the context before calling postconstuct or create
I assume this is done deliberately. But I don't understand why it is done like that - anyone know why?Assuming the Component.java is correct then it means @Create can't safely be used in Application-scoped components (or indeed any other cotext that has multi-thread access).
Can any of the seam team comment on this?
Thanks in advance, Pete.
-
2. Re: Seam's MailSession is not Thread safe
pbrewer_uk Feb 26, 2010 5:15 PM (in response to pbrewer_uk)This also applies to QueueConnection too.
Can anyone comment on this behaviour - shall I raise a JIRA for this behaviour?
Thanks, Pete.