Maybe this questions stems from the fact that I haven't buckled down and bought 
an EJB3 book yet (I do mostly pojo work with Seam).  But, it also relates to 
application-scoped pojos, so I want to understand.

The reference documentation makes it clear you can have a stateless bean that 
uses injected variables.  But it also mentions that stateless beans can be 
accessed concurrently.  So, what prevents the injected variables from being 
overwritten by injection from another concurrent thread?

I.e, what keeps the following scenario from happening?


  | @Stateless
  | @Name("bean")
  | public class Bean {
  | 
  |    @In EntityManager entityManager;
  | 
  |    @In Long id;
  | 
  |    public void doStuff() {
  |       ...
  |       //(a)
  |       entityManager.find(Entity.class, id);
  |       //(b)
  |    }
  | 
  | }
  | 

1. Thread A calls doStuff()
2. Seam interceptor sets entityManager and id
3. Thread A gets to point (a)
4. Thread A pauses
5. Thread B calls doStuff()
6. Seam interceptor sets entityManager and id (different values than thread A)
7. Thread B gets to point (b)
8. Thread B pauses
9. Thread A wakes up
10. Thread A executes the find() with the wrong entityManager and the wrong id

The same question applies to application-scoped components.

Thanks

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4083758#4083758

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4083758
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to