Solved

Need suggestion regarding Multi-threading/singleton

Posted on 2008-06-10
4
629 Views
Last Modified: 2010-04-21
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
Comment
Question by:srikanthradix
  • 2
  • 2
4 Comments
 
LVL 92

Expert Comment

by:objects
ID: 21756084
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
 

Author Comment

by:srikanthradix
ID: 21762182
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
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 21764622
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
 

Author Closing Comment

by:srikanthradix
ID: 31465965
Thanks for the solution.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
userCompare  challenge 3 69
topping1 challenge 7 73
eclipse argument 14 53
netstat -ano | find "8000" and taskkill /f /pid 2984 3 39
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now