views:

62

answers:

1

Using EJB entity beans you can configure the bean so that when a thread has access to an EJB entity bean, no other threads can access the EJB bean. The container will block other threads until the thread with the lock is finished with the bean. Is there a "Spring way" to do this? Or do you have to just use the standard Java concurrency synchronization approaches to handle this?

+1  A: 

If you're referring to pre-EJB3 entities, then this model is a bit broken, and probably not one you want to be following. Concurrent access to the same java object instance of a persistent entity should be avoided. Instead, each thread should obtain its own instance of the entity from the container.

The usual approach to controlling concurrent access to entities is to use transactions, and let the database take the strain. Spring+Hibernate/JPA is more than capable of this.

skaffman
Thanks. That was what I was referring to.
Marcus