Announcement Announcement Module
No announcement yet.
Singleton? Or not Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Singleton? Or not

    I am new to spring, and I am apologize if my question is stupid. I started to use spring frame work at current project but was not sure about the spring singleton configuration.

    A bean was set up in spring config xml with -- singleton="true" --. So I am assuming this bean “instance” will be at most one in application context scope. And I was using a single thread in the bean to do scheduled work by using JDK5.0 java.util:

    java.util.concurrent.Executors.newSingleThreadSche duledExecutor()

    from the debug out put, there were two thread pools running and each pool has its own thread run the job. Which ends up two threads to do scheduled work. From JDK5.0 jave doc it says:

    Creates a single-threaded executor …
    Tasks are guaranteed to execute sequentially, and no more than one task will be active at any given time.

    I am confused if there were two instances of beans with its own thread. In other words, is this configuration guaranteed a singleton?

    Here is my configuration:
    <bean id="testManager" class="org.someOrg.service.testManagerImpl" singleton="true">
    <property name="oneDAO">
    <ref bean=" oneDAO "/>

    Thanks in advance for any suggestion

    out put:

    [app] DEBUG [pool-1-thread-1] testManagerImpl.updateCount(860) | ======

    [app] DEBUG [pool-3-thread-1] testManagerImpl.updateCount(860) | ======

    [app] DEBUG [pool-1-thread-1] testManagerImpl.updateCount(860) | ======