Solved

Need suggestion regarding Multi-threading/singleton

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

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.

744 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

12 Experts available now in Live!

Get 1:1 Help Now