DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • Apache Kafka vs. Message Queue: Trade-Offs, Integration, Migration
  • Working on an Unfamiliar Codebase
  • Playwright JavaScript Tutorial: A Complete Guide
  • Front-End: Cache Strategies You Should Know
  1. DZone
  2. Coding
  3. Frameworks
  4. Stateless EJBs: Pooling and Lifecycle

Stateless EJBs: Pooling and Lifecycle

Abhishek Gupta user avatar by
Abhishek Gupta
CORE ·
May. 12, 14 · Interview
Like (0)
Save
Tweet
Share
4.25K Views

Join the DZone community and get the full member experience.

Join For Free

a summarized view (notes) of the stateless ejb pooling and life-cycle. useful for newbies . . . . .

ejb pooling: quick overview

  • ejb instances are stored in a location known as the ejb pool – this is nothing but an in-memory cache .
  • stateless ejbs are generally instantiated on-demand i.e. as and when the client invokes a method on the bean.
  • however, most application servers also provide a facility wherein they can be configured so that the ejb pool can be populated at start up with certain number of instances e.g. in weblogic, this can be configured within the weblogic-ejb-jar.xml by stating the exact number in the initial-beans-in-free-pool element.

pooling benefits

  • improved performance
  • client doesn’t need to wait until the bean is instantiated in order to service the request

stateless bean lifecycle

slsb-lifecycle

slsb states : non_existent, inactive, busy

non_existent – this is a scenario where the bean does not yet exist in the ejb pool (has not been instantiated)

inactive – it is a state where the ejb instance already exists in the ejb pool but is not servicing a client request

busy – an ejb instance is summoned in order to service a client request, and as a result it goes into a busy state.

an ejb instance is summoned in order to service a client request, and as a result it goes into a busy state. an ejb can go into a busy state from either inactive or non_existent states

slsb state transitions

inactive to busy – as the name suggests, an inactive bean in the pool was chosen to cater to the client invocation

non_existent to busy – a fresh ejb instance was created in order to serve a client request

busy to inactive

an ejb can go from a busy state back to an inactive state i.e. after servicing the client request, the instance goes back to the pool

inactive to non_existent

an ejb instance can also be destroyed under certain scenarios by configuring a time out which forces the application server to remove all ejb instances in the pool which have been inactive for a certain time interval . however, app servers do ensure that the ejb instance count does not go below the minimum number of permissible instances (configurable property – read above)

note : this primarily done in order to conserve the amount of memory which is consumed by the pooled ejbs since they are cached there. if there are a lot of unused instances, they can be removed in order to optimize memory consumption. the container can create new instances on-demand

what happens when a client invokes a method on a stateless bean?

scenario 1 : a fresh instance of the bean is instantiated by the container.

why does this happen?

possible reasons are

  • there are no beans in the ejb pool to begin with – the app server was not instructed to pool a default number of beans on server startup
  • all the beans in the ejb pool are busy servicing requests from clients, but the total bean count  in the pool is less than the maximum number of instances which are permissible (a configuration parameter)

scenario 2 : an existing instance of the bean is returned by the container

possible reasons

  • there are certain number of ejb instances available in the pool and they are not in a busy state i.e. they are not participating in a servicing a client request. one such instance is just returned by the container
  • there were certain number of ejb instances available in the pool but all of them are in a busy state and the maximum permissible number of beans in the pool has already been reached. the client application has to wait until one such bean becomes free and is available to cater to the client request

scenario 3 : the client request is not services (receives an exception)

possible reasons

if the maximum permissible number of beans in the pool has already been reached and the none of the busy beans become available within a certain time frame

Bean (software) Spring Framework Requests

Published at DZone with permission of Abhishek Gupta, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Apache Kafka vs. Message Queue: Trade-Offs, Integration, Migration
  • Working on an Unfamiliar Codebase
  • Playwright JavaScript Tutorial: A Complete Guide
  • Front-End: Cache Strategies You Should Know

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: