This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes a MDB question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "a MDB question" Watch "a MDB question" New topic
Author

a MDB question

dennis liang
Greenhorn

Joined: Dec 15, 2006
Posts: 9
I have a MDB and set max session to 10 in order to improve performance. so I have 10 threads for this mdb.
inside the mdb,a same stateless session bean is used in different methods. No data is shared in the session bean, just make logic calls
should I create a member varible in mdb that all threads can share or use jndi to get seesion bean each time to make a logic call?
first solution will only use one session bean, if different threads use the same method concurrently, will cause any problem?looks like a baisc question, but I am just not very sure.
second one will hurt performance
Thanks
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

>should I create a member varible in mdb that all threads can share or use jndi to get seesion bean each time to make a logic call?

jndi to get session bean always.

cheers,
ram.
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 511
Hello there,
There will not be 10 threads as you mentioned. There would be 10 MDB instances in the instance pool.
And each will have its own reference to the Session bean (Injected or obtained by explicit JNDI lookup).
should I create a member varible in mdb that all threads can share or use jndi to get seesion bean each time to make a logic call?
first solution will only use one session bean, if different threads use the same method concurrently, will cause any problem?looks like a baisc question, but I am just not very sure.


As I have mentioned above you should not worry about the Threads and concurrency here. Only thing you have to keep in mind while programming MDB or Stateless Session bean is that if you have any state in your bean, you cannot be sure if that would be available for next method call. This is because instances are swapped amongst executions of various requests.

But in your case if you decide to inject the SLSB in your MDB, and you dont have any state i.e. member variable which will get change during your business logic execution then it would not pose any problem. To improve performance you have multiple instances in the instance pool to serve the request and hence nothing to worry about there in this regards.

regards,
amit
Mahesh Trikannad
Ranch Hand

Joined: Dec 14, 2004
Posts: 66
Sorry to come in late on this. I have a question. Why use a stateless session bean ? Why not invoke POJO's directly from MDB.
What benefit is the stateless session bean giving you ?


Mahesh Trikannad
ntumba lobo
Ranch Hand

Joined: Oct 21, 2008
Posts: 180
Blindly I would say
a) SLSB can be injected with DI in the MDB. And in turn the SLSB can get injected any other JNDI resource if required by the EJB container.
b) SLSB logic can participate in a JTA transaction initiated in the MDB
c) no threading issue for logic in SLSB

but it's true that if there is no need for the services of the EJB cnotainer a POJO would do just fine


SCJP 5 , SCWCD 5, SCEA 5
 
jQuery in Action, 2nd edition
 
subject: a MDB question
 
Similar Threads
MDBs with a JDBC conneciton
Transactions and MDBs
can i use one entity bean to access more than one tables
A design in practise
Basic Object Pooling doubt