Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8319529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:21:21+00:00 2026-06-08T22:21:21+00:00

In a code base that I’ve inherited, there’s an MDB which is calling SingletonBeanFactoryLocator().getIntance().useBean()

  • 0

In a code base that I’ve inherited, there’s an MDB which is calling SingletonBeanFactoryLocator().getIntance().useBean() to get a factory reference in its ejbCreate(), and then getting a specific bean from this factory and storing it as an MDB instance variable. (The factory is of type ‘ClassPathXmlApplicationContext‘).

The confusing part is: after that bean is obtained, it’s calling ‘release()‘ on this factory reference in that same ejbCreate().

Now, this MDB is pooled with poolsize ‘x‘ and what I’ve observed is, beans defined in the context xml are getting created ‘x‘ number of times. So my guess is, every time the ‘ejbCreate()‘ executes, it’s creating a context and its beans afresh.

I checked Spring doc for ‘release() above which says:

In an EJB usage scenario this would normally be called from `ejbRemove()` and `ejbPassivate()`.

So here’re my questions:

1) is it really creating a new context and new beans everytime ejbCreate() is called?

2) if yes, what happens to the context/beans created in the previous call (e.g. if the beans are singleton themselves, will they be destroyed)?

3) is this the right way to use SingletonBeanFactoryLocator (possibly for thread safety issues) in the context above?

4) if not, what is the right way to use it?

EDIT: one possibility I can think of is to make the concerned beans prototype to make each MDB instance thread-safe, so there’s no need to release and recreate the context. Awaiting other comments/suggestions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:21:23+00:00Added an answer on June 8, 2026 at 10:21 pm
    1. Yes
    2. Nothing happens. The same objects will still be in the same MDBs. The MDB doesn’t care and Spring is out of the picture at this point.
    3. That really depends on the use circumstances. If you just use Spring to assemble objects and every MDBs should have it’s own instances then the answer is yes.
    4. Depending on the use case SpringBeanAutowiringInterceptor may or may not be a better alternative.
    5. Prototype can be tricky. You have to understand your beans and the consequences well to make it do what you expect. That’s why it’s generally best to make spring beans stateless.

    Update:
    There is actually a race condition. If the container decides to run the ejbCreate() of two MDBs in parallel then they both will end up sharing the same application context.

    Update 2:
    I could not find a section that explicitly allows EJB creating through parallel threads but I could also not find a section that explicitly forbids it.

    Given the following sections from the spec I assume it would be in the spirit of the spec to do it.


    2.4.2 Message-Driven Objects

    A typical EJB container provides a scalable runtime environment to execute a large number of mes- sage-driven objects concurrently.

    5.2 Goals

    A further goal of the message-driven bean model is to allow for the concurrent processing of a stream of messages by means of container-provided pooling of message-driven bean instances.

    5.4 Protocol Between a Message-Driven Bean Instance and its Container

    It is the container’s responsibility to ensure that the message-driven bean comes into existence when the container is started up and that instances of the bean are ready to receive an asynchronous message delivery before the delivery of messages is started.

    5.4.11 Concurrency of Message Processing

    A container allows many instances of a message-driven bean class to be executing concurrently, thus allowing for the concurrent processing of a stream of messages. No guarantees are made as to the exact order in which messages are delivered to the instances of the message-driven bean class, although the container should attempt to deliver messages in order when it does not impair the concurrency of mes- sage processing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is there any development environments that allow you to have one code base that
Is there a consistent code-base that allows me to upload a zip file to
I inherited a moderately large sized code base that makes extensive use of mysql_fetch_assoc
I have an inherited code base that was developed in .NET 1.1. When I
is there any objective c frameworks/code base that help you to develop a rss
I have inherited a code-base that uses ASP.NET MVC 3. I'm learning it as
I have inherited a code base that makes use of the Castle Windsor IoC
I've inherited a long term maintenance code base that has two radically different iPhone
I have a code base that has been used as an ASP.Net web application.
I have an existing code base that is not packaged at all. The code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.