• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

a MDB question

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>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.
 
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Are you here to take over the surface world? Because this tiny ad will stop you!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic