How to replace singleton design pattern and with which design pattern ?

I have singleton class to update the database it is causing delay for requests as requests queue to update. How can replace this class with which design pattern I have to update the data?
Laxman PotadarAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

krishna kishore mellacheruvu venkataCommented:
Why do you have chosen single ton pattern for this? Did you try DAO pattern?

DAO design pattern will be good for data base updates.
Jim CakalicSenior Developer/ArchitectCommented:
Can you post the code for your class and maybe a couple unit tests or examples of how clients use it? This would be helpful in understanding your design context and allow a more appropriate and concrete answer to your question.
Jim CakalicSenior Developer/ArchitectCommented:
By itself, having a singleton class for database update/access probably isn't the cause of your problem. Krishna asks, "why not try the DAO pattern?" DAO and Repository are common patterns for allocating responsibility to classes to hide the details of database access. You'll even find first class support in frameworks like Spring. The "ugly truth" is that DAOs/Repositories are frequently (almost always in my experience) implemented as "singletons". When configuring a bean in Spring, one of the properties a developer can choose is scope. By default, Spring configures and creates beans with "singleton" scope meaning that there will be just one instance of the class and all injected references will be the same instance. Using Spring, many beans including DAOs and Repositories are in fact singletons because Spring won't ever create more than one. A class could implement both the DAO and Singleton patterns -- they are not mutually exclusive and are frequently encountered together even in (especially in?) high performing multi-threaded systems. So, Singleton probably isn't your problem. Posting your code will help us identify where perhaps the real culprit lies.

The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

If you have a Singleton class that is shared between multiple threads (e.g. multiple requests) then to work correctly it should be synchronized (unless it never changes value).

As a result, it can cause delays as each thread will take turns accessing the data - rather than working in parallel.

There are lots of possible solutions - basically anything where the data isn't shared between threads (each thread/request instead gets its own copy of the data) will generally raise performance.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jim CakalicSenior Developer/ArchitectCommented:
Hi, Laxman. Did you need more help with his question?
Laxman PotadarAuthor Commented:
hi Jim , Pearson & Krishna,

I had implemented singleton class used with Servlet.  which caused issue. Yes we have not used DAO.  It was synchronised and caused the delay . As solution accessibility of singleton is done in parallel and now I don't have issue. Thanks for your help.
Cool - glad it's solved.

Laxman PotadarAuthor Commented:
Thanks for your inputs.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.