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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:37:21+00:00 2026-05-13T18:37:21+00:00

I have a singleton ejb which is getting initialised twice. I have no idea

  • 0

I have a singleton ejb which is getting initialised twice. I have no idea why and it is completly defenting the point in having a singleton bean as far as I can tell. Any help will be appreciated. As you can see I tried to put a static boolean in to prevent the multiple initialisation (not that it should be required) but it made no difference.

Bean:

@Singleton 
@Startup
public class DataModelBean implements DataModelBeanLocal {

   private static Logger log = Logger.getLogger(DataModelBean.class.getName());

   @PostConstruct
   public void init(){
      log.info(this);           
   }
}

Log output snippet:

2010-02-17 16:06:13,670 INFO  [AutoDeployer        :DataModelBean       ] com.xxx.xxx.datamodel.DataModelBean@117843d
2010-02-17 16:06:14,233 INFO  [AutoDeployer        :DataModelBean       ] com.xxx.xxx.datamodel.DataModelBean@62b9d3

Is it creating 2 beans!! or is it deploying the app twice?

As an aside I am using glassfish v3, is this mature enough? Should I use v2 or something else? Thoughts?

  • 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-13T18:37:22+00:00Added an answer on May 13, 2026 at 6:37 pm

    The following singleton:

    @Singleton
    public class MasterDataCache 
    {
        private final static Logger logger = LoggerFactory.getLogger(MasterDataCache.class);
    
        private Map cache;
    
        @PostConstruct
        public void initCache() {
            logger.debug("initCache()");
            this.cache = new HashMap();
        }
    
        public Object get(String key){
            return this.cache.get(key);
        }
    
        public void store(String key,Object value){
            this.cache.put(key, value);
        }
    }
    

    And the following servlet:

    @WebServlet(name="SingletonTester", urlPatterns={"/SingletonTester"})
    public class SingletonTester extends HttpServlet {
    
        @EJB
        MasterDataCache masterDataCache;
    
        @Override
        public void init(){
         masterDataCache.store("startup", new Date());
        }
    
        public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            PrintWriter out = response.getWriter();
            try {
                out.println("Startup time: " + masterDataCache.get("startup") );
            } finally {
                out.close();
            }
        }
    }
    

    packaged as a war works as expected when deployed “manually” under GFv3. It also deploys fine and works as expected under NetBeans (the initCache is called once only). My only problem is that the deployment fails under Eclipse (GFv3 complains about eclipseApps/$projectName not containing any EJB module, which are however in eclipseApps/$projectName/WEB-INF/classses). Sadly, this seems to be a bug with the GlassFish Eclipse plugin (at least the version I’m using). I don’t see many issues in the issue tracker though… weird because this looks like a big blocking one. But outside Eclipse, GFv3 behaves normally, I couldn’t reproduce your issue.

    Update: I finally got things working under Eclipse and GlassFish v3. I won’t give all the details but the problem is that I somehow failed to get my project directly recognized as a “Dynamic Web Module” 2.5, the version was initially set to 2.3 and I think this had something to do with the deployment error on GFv3. After settings up my project correctly (with a facet set to 2.5), deploying it worked fine. So I just screwed up myself.

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

Sidebar

Ask A Question

Stats

  • Questions 347k
  • Answers 347k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yes, this is standard behaviour in the non-language-specific unicode collations.… May 14, 2026 at 6:16 am
  • Editorial Team
    Editorial Team added an answer Try this: a.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE | BIF_EDITBOX; May 14, 2026 at 6:16 am
  • Editorial Team
    Editorial Team added an answer When you use addProperty this automatically adds it to the… May 14, 2026 at 6:16 am

Related Questions

I am currently working on some older java code that was developed without App
I have a singleton that uses the static readonly T Instance = new T();
I have a singleton class that inherits from sprite so that it can access
I have a singleton service with a dependency on a service with a request
I have a singleton bean which needs for each call of a function to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.