Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Need suggestion regarding Multi-threading/singleton

Posted on 2008-06-10
Medium Priority
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">
                        <entry key="0">
                              <bean class="com....BusinessServiceFullfillment"></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.
Question by:srikanthradix
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 92

Expert Comment

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.

Author Comment

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.

LVL 92

Accepted Solution

objects earned 2000 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

Author Closing Comment

ID: 31465965
Thanks for the solution.

Featured Post

What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

Question has a verified solution.

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

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.

670 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