• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is use of singleton-pattern questionable?

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Folks,
I have designed my project with basic singleton-pattern, i.e. singleton java beans calling DAO to perform DB operation. These beans are then referred by a WEB project's controller classes to invoke data operations. My intention to create a Service-layer & DAO with singleton-pattern is to reduce number of objects in the heap. But would this be a problem, when application's user base is large, i.e. would it really slow down the performance if I run load-testing on the application?

This is really urgent for my project. Do help me out.
 
Ranch Hand
Posts: 265
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my experience, it's fairly standard practice to have a single instance of each Controller and each Data Access Object (DAO) in your application.

Especially for the DAO, you can coupled the singleton pattern with a good JDBC pooling implementation to minimize performance problems.
 
Subhadip Chatterjee
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Stevie for the reply...you know what, I'm using struts framework for display & user request Controllers (Action servlet & Action classes). So, I can't possibly have single instance for Controllers.

From the Action class, I'm making call to the singleton POJO class, that uses one DAO class (sometime a DAOFactory to map proper DAO) to perform a DB operation. This DAO is also singleton.

My concern is in load testing, when say a load of 50 concurrent users will be tested, would this singleton-design may slow down the application? (50 user threads are trying to use same instance of POJO class & same instance of DAO to perform one DB job)would there be any locking on POJO may happen?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic