Link to home
Start Free TrialLog in
Avatar of srikanthradix
srikanthradixFlag for United States of America

asked on

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.
Avatar of Mick Barry
Mick Barry
Flag of Australia image

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.
Avatar of srikanthradix

ASKER

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.

ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the solution.