Announcement Announcement Module
Collapse
No announcement yet.
Four instances of EVERY singleton being created!!! Help! Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Four instances of EVERY singleton being created!!! Help!

    I'm using spring with tomcat, and the app seems to work fine, but now I'm going some caching stuff, and I'm running into problems. It appears that I'm getting four instances of every "singleton" created in the app. If I put a log message in like log.error("Object address: " + this); into the code,
    then it spits out four different object addresses, four different times. If I put a breakpoint into my debugger inside a "singleton" constructor, it calls it four times (multithreaded)! What the heck is going on? Why is my spring container duplicating everything four times (well, three times)????

    Anybody?

    Thanks in advance,

    Jerry

  • #2
    Are you creating spring containers?

    Code:
    $ find src/main/java -exec grep 'new .*ApplicationContext' {} /dev/null \;

    Comment


    • #3
      Yes, I am creating containers (I think)

      I've got an applicationContext.xml and a dispatcher-servlet.xml. Both of them fire up the proper objects, and some of the objects in dispatcher-servlet.xml depend on (and are properly created with) objects from applicationContext.xml. This is an application that is already running fine in production. I have a feeling these multiple instances may be happening only on my windows machine. I did notice that I have several build template properties files in my config directory. Maybe it's creating an application context for each of these. When I do builds using ant for staging and production, these are not included in the config directory. Only one gets created called config.properties. But that doesn't really make sense either. And that will be easy to test when I get back to work on Monday. I'm really curious as to why this is happening. I can also have stuff spit out to logs to see if it's doing it after running with a war created from the ant script I just mentioned. Any more ideas anyone?

      Comment


      • #4
        Please post your singleton class code.......

        Comment


        • #5
          There are a few things here. Are you explicitly creating containers, which I think David was talking about e.g. in the code. Also do you have multiple Listeners/Servlets setup to load the containers?

          Comment


          • #6
            I figured it out

            My virtual hosting settings in server.xml were set as webapps as the docroot, instead of the context directory, so each virtual host was running all the apps under webapps directory (creating multiple instances of the app). I've fixed it. Now a singleton is truly a singleton once again.

            Thanks.

            Jerry

            Comment

            Working...
            X