• 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

DAO factory and database performance

 
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all:
if DAO factory frame work is used in a multi- threaded J2EE project, when is it appropriate to cach a single object and return it over and over again, vs. retruning a brand new object.
for example:
//cached object
public class DAOFactory
{
privte EmployeeDAO MyEmployeeDAO = new EmplyeeDAO();
public EmplyeeDAO getEmplyeeDAO();
{ return MyEmployeeDAO;}
}
vs.
//new object
public class DAOFactory
{
public EmplyeeDAO getEmpoyeeDAO()
{ return new EmplyeeDAO();}
}
I really appreciate it if someone can explain to me in what situation should I use which technique, and if there is any performance implication in using any of them.
thanks
[ April 22, 2004: Message edited by: Hanna Habashy ]
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hannah,
If your DAO has a reference to any external object, you would want to cache it. For example, the DAO could read in the user id/password from a properties file.
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeanne:
I don't understand your answer. If my DAO reads from an external object, like user name and password, why I would want to cach it? In this case the DAO object will be unique to that user, and I can't give the same DAO object to another user.
Maybe I didn't explain my question in a good way. In my question, I meant should I make the DAO classes as singletons, or not. In my mind, the DAOs are worker classes. User ask the controler about what they want, the controler delegate it to the DAOs, the DAOs do the job, then return it back to the controler. Does it matter if I have many objects of the same DAO, or one object can handle all the work?
Thnks
[ April 23, 2004: Message edited by: Hanna Habashy ]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you DAO's thread-safe (don't have any instance variables)? If so you can return a singleton, if not create a new instance each time.
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hanna,
Not the user's id and password. The database username and password. Usually in a J2EE application, users log in (say through a web interface) and the server (DAO) submits requests to the database on their behalf. The individual users don't get separate ids to the database.
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it. Thank you all
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic