开发者

Java EE concurrency question

I wrote an application that is using beans for creating and storing books(titles,authors etc) to the database. The basic fu开发者_运维知识库nctions for adding and deleting books are implemented in a local stateless bean.

My problem is that I don't quite get how this would work in a concurrent way. If two users would like to get a handle on the managing bean at the same time would this work by default? And if so how exactly does it deal with concurrent requests?

Thanks

Note: Only creation and deletion should be supported.No editing! So I suppose that there are no conflicts there in terms of writes and reads!


There can only be one calling thread per EJB instance at a given time. EJBs are (most of the time) pooled by the container: if two clients call the same method (or different methods on the same EJB type) they will be given different instances by the container or one will have to wait until one instance is ready to handle its call.


They would get a different instance of your managing bean. It would work by default, if your managing bean is indeed stateless.

The concurrency is handled by the database and its support for transactions. If a transaction tries to modify a book that is being deleted by another concurrent transaction (for example), one of the transactions will rollback, due to a SQLException thrown by the database driver when committing the transaction.


What kind of client technology do you use?

If you use a web interface you could use the Gateway pattern (a stateful session bean and an extended perstence context, see "Real World Java EE Patterns – Rethinking Best Practices" by Adam Bien) and just return the attached entity.

If you have a remote client, you probably want to return a DTO with a business key, which uniquely identifies the entity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜