Announcement Announcement Module
Collapse
No announcement yet.
Two instances of a singleton created for timer tasks Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Two instances of a singleton created for timer tasks

    We are using ScheduleTimerTasks in our application. We understood the classes that are called by the timer tasks would only be instantiated once, as in a singleton, because beans in spring are singletons by default.

    We are seeing these beans getting instantiated each time the timer task fires. It appears that the method that is invoked in the beans is getting invoked the same number of times as there are tasks defined in the scheduledtask entry in the applicationContext xml file.

    Is this the expected behavior of the scheduled task timer?

    After putting a profiler on the spring framework, we see that there are actually 2 instances of the framework container being created.

    Why are 2 instances of the framework being created? (We are running on a core duo machine i.e. 2 cpu machine).

    We are running the Spring framework on top of tomcat with a hibernate/postgresql data layer.

    TIA,

    Todd

  • #2
    Originally posted by tnash View Post
    Why are 2 instances of the framework being created? (We are running on a core duo machine i.e. 2 cpu machine).
    What do you mean exactly? Are there two instances of *ApplicationContext? That might be normal if one is the child of the other? If not it sounds very suspicious and certainly isn't normal behaviour for any web application in the setup you briefly described. Are you initialising with a normal ContextLoaderListener?

    I'm not sure I follow your point about the tasks. But a singleton bean is only created once per BeanFactory (ApplicationContext whatever...) in normal circumstances, so you are correct to be alert to possible issues.

    Comment


    • #3
      Two instance of a singleton created

      I have done a bit more investigation on this and found that there are two instances of any singleton bean being created when Spring starts up.

      We aren't doing any inheritance of the applicationContext file or anything out of the ordinary.

      Not sure whether or not I have done anything to cause the dual instances to be created through some configuration file, but any help would be most appreciated.

      Todd

      Comment


      • #4
        Check that you're not loading the same XML config twice

        If you reference the same XML in more than one section in your web.xml all the beans in there will be loaded twice.

        Comment

        Working...
        X