Solved

Need suggestion regarding Multi-threading/singleton

Posted on 2008-06-10
4
633 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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
countHi2 challenge 7 60
java 8 lambda expresssions exception handling 3 101
github account with ecipse 1 53
replace a word with other 1 45
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
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…
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.

832 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