Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 653
  • Last Modified:

Need suggestion regarding Multi-threading/singleton

My Application will called by many threads. I have configured my application such that the configuration is
      
      <bean id="ServiceFullFillmentCoordinator" class="com....BusinessServiceCoordinatorImpl" singleton="false">
            <property name="businessServices">
                  <map>
                        <entry key="0">
                              <bean class="com....BusinessServiceFullfillment"></bean>
                        </entry>
                  </map>
            </property>
            
      </bean>

As you can see "BusinessServiceCoordinatorImpl" bean's singleton is set to false but the BusinessServiceFulfillment bean's singleton is set to true as it is true by default. So, when multiple threads calls my Application will there be any problems since the property of the bean is set as singleton=true? Please suggest.
0
srikanthradix
Asked:
srikanthradix
  • 2
  • 2
1 Solution
 
objectsCommented:
whether it is a singleton or not really has nothing to do with whether it is thread safe or not.
You need to ensure that the code in your bean is thread safe.
0
 
srikanthradixAuthor Commented:
Doesn't singleton=true means thread-safe?

My Understanding of singleton
Creates single object for all threads and when one thread is using this object, other threads has to wait until the thread that is using the object relinquishes control of it.

And also, I have one more question singleton=false

Does singleton=false means creates seperate objects for each and every thread?

Please correct me if I am wrong.

0
 
objectsCommented:
no, it just means that only a single instance of the bean would be created.
That bean could still be accessed by multiple threads, thus it needs to be thread safe.

> other threads has to wait until the thread that is using the object relinquishes control of it.

I don't believe that is the case

> Does singleton=false means creates seperate objects for each and every thread?

Just checked and that is correct, so non-singletons should be thread safe

http://static.springframework.org/spring/docs/1.2.x/reference/beans.html#beans-factory-modes
0
 
srikanthradixAuthor Commented:
Thanks for the solution.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now