• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Why have more than one stateless session bean?

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm getting confused by something about stateless session beans.
The spec and books talk about creating multiple instances of stateless session beans, keeping inactive stateless session beans in a bean pool, and so on.
If a stateless session bean truly has no state (i.e., no instance variables), there is never a need to create more than one instance of the bean.
I presume that the point of confusion here is that stateless session beans are allowed to have instance variables and state, but that this state only persists for the duration of one call from a bean client. Can someone confirm that for me?
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Multiple instances of stateless session bean can service multiple client requests at one time. Stateless means that they do not carry any state from one method invocation to another and hence any client thread can use them
 
Ranch Hand
Posts: 8944
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moreover, SLSB avoid the costly creation and descrution of objects.
 
Bill Pugh
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure those responses really solve my confusion.
To put it another way, does the spec guarantee that while one client is invoking a method on a stateless session bean, no other client will invoke a method on that session bean? That would mean it would be safe to have state stored in instance variables so long as that state didn't persist past a single call from a client.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bill,
EJB's are single threaded, hence only one method invocation can be executed on an EJB at a time. Therefore, as previously mentioned the Container can spawn multiple instances of stateless session beans to handle multiple client invocations.
The term stateless simply means theres no affinity between method invocations from a client to stateless sb. But, just like any java object its can have state, but its not associated to any single client.
hope this helps.
Rowan
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic