File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes Stateless sesssion beans & Transactions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Stateless sesssion beans & Transactions" Watch "Stateless sesssion beans & Transactions" New topic

Stateless sesssion beans & Transactions

Roland Winter

Joined: May 11, 2003
Posts: 7
I'm using stateless session beans for the project I'm currently working on. I understand that the container can instantiate as many instances of each bean as it feels it needs.
I have one particular method that requires that it is the ONLY one running at any one particular time no matter which instance it was invoked on.
Does the container handle this automatically or do I need to specify something on the method, at deployment time or . . . .I don't know what else there is.
Any suggestions/solutions will be greatly appreciated
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
How about extracting that one method into a separate bean and configure the maximum pool size to 1 using the vendor deployment descriptor? Otherwise you'd have to either make a similar limitation to the whole bean, or play with the synchronized keyword, which is a bit dangerous (disallowed by the specification).

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Roland Winter

Joined: May 11, 2003
Posts: 7
Excellent idea Lasse! Thanks, I'll give that a go.
I agree. Here's the link:
subject: Stateless sesssion beans & Transactions
It's not a secret anymore!