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 323651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:03:02+00:00 2026-05-12T09:03:02+00:00

When you want to call an EJBBean from the client, first you need to

  • 0

When you want to call an EJBBean from the client, first you need to get hold of an EJBHome object reference through JNDI lookup. This code needs to be executed each time you need to work with the EJBBean so is gets redundant and expensive.

To solve this problem, you can cache the EJBHome object references and reuse them again and again from the cache without repeating the JNDI lookup.

This is the EJBHomeFactory Pattern (or a more generic Service Locator Pattern).

The majority of implementations I have seen use a synchronized Map as the cache, or a Hashtable. If the cache is constructed when the application is deployed on the server and no modifications are made to the cache afterwards (only get() methods are performed) do I really need a synchronized Map or a HashMap will do?

I know HashMap is not safe if at least one of the threads modifies the map (there is even a SO post on this here) but in this case threads only perform reads.

So, is a HashMap safe to use in the EJBHomeFactory Pattern?

  • 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-05-12T09:03:03+00:00Added an answer on May 12, 2026 at 9:03 am

    If you can guarantee the life-cycle is as you describe it seems clear that the unsynchronized HashMap should be OK. However, my instinct is that this is building in a brittle dependency on your current deployment pattern.

    If you use a synchronized datastructure then you know it’s safe now and in the future. Unless you have concrete evidence that the synchronisation is truly impacting performance I would go with the “obviously correct” implementation.

    In passing, several leading app servers actually cache the results of JNDI lookups so it’s not clear how much saving the pattern your using actually gives – though I must admit I do tend to use it myself.

    EJB references themselves can be reused, so in fact the frequency of going to the home can be kept quite low. If extreme performance is the objective this may be a further avenue to explore.

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

Sidebar

Related Questions

I want to call some RESTful web services from a J2ME client running on
I want to call a function from a .NET DLL (coded in C#) from
I want to call a c# function from my javascript function. I have a
I want to call my .NET code from unmanaged C++. My process entrypoint is
I want to call an ASHX file and pass some query string variables from
I want to call a web service, but I won't know the url till
I want to call a few static methods of a CPP class defined in
I want to call ShowDialog() when a keyboard hook event is triggered, but I'm
I want to call a function (which calculates my version number) when my NSIS
If I want to call Bar() instead of Foo() , does Bar() return me

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.