Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Webpshere 5.0 + stateless beans

 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I've tried to run a stateless session bean that holds the role of a counter (code is extracted from Howard Kushner's book Developping J2EE Application with IBM Websphere Studio)
Here's the code of the bean:

Well, all is OK when I run this bean via the Universal test client. But, i'm not clear about something.
As far as I have understood, in case of stateless beans, the same client won't necessary call the same bean through its different method calls. Or, when I call merely times the increment method via the UNiversal Test Client, the counter's value increment of one unit each time.
It means 0 ->1 ->2 -> 3 -> 4. I would expect that the value will not increase so regulary and that I would have for example 0 -> 2 -> 1 (because the second time, the client would have asked for another bean instance).
So, shall we conclude from this that only one instance of this stateless session bean is created by Websphere EJB container?
Thanks for any light on this topic,
Regards,
Cyril.
 
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Cyril,
from that example, we can conclude that the container used only one bean instance to serve your client. But it may have more than one instances in the pool.
You may put a print message to the setSessionContext or ejbCreate methods to know how many bean instances are created. This value may be configured in the app server.
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Cyril,
One of the interesting point for stateless session bean is that, there will be a instance pool that hold by the container.
When there are several requests coming in, the container picks up an idle bean to serve the requests randomly. If there are not enough idle beans to serve the requests, it will create more until it reaches the max. no. of instances.
In your case, since there is always 1 request, it may not be surprised that there is only 1 instance created by the container to serve the request. If you write a multi-thread program and, say, call the bean 1000 times, you may get your expected outcomes.
Nick.
 
I've read about this kind of thing at the checkout counter. That's where I met 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