permaculture playing cards*
The moose likes Servlets and the fly likes Optimizing sevlet performance with a database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Optimizing sevlet performance with a database" Watch "Optimizing sevlet performance with a database" New topic
Author

Optimizing sevlet performance with a database

Tod Checker
Greenhorn

Joined: Feb 19, 2004
Posts: 27
Hello I have a design question.
Where is the best location on a servlet to access a database (assume a connection pool exists), and is database activity optimal when synchronized or left alone, for a high volume site?
When I say location on a servlet I mean, is it best to just write it in the service methods?
Or
Is it better to write it in its own method outside the service method?
Or
Is it better to write it in its own class which is instaniated and called within a service method or in singleton class which is shared among the site?
And is performance boosted if synchronization is used?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

If your application follows an MVC pattern (and it should), database access should be abstracted away from the servlet, which is part of Controller, into classes that are part of the Model.
Synchronization never improves performance. You synchronize to prevent thread safety issues, not to boost performance.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tod Checker
Greenhorn

Joined: Feb 19, 2004
Posts: 27
So you think it is best to leave them in seperate classes and instaniate them in the service classes?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Optimizing sevlet performance with a database
 
Similar Threads
multithread in servlet container
To Nikhil Pendharkar for IBM 287
need support to implement this idea
Is this considered MVC?
J2EE Recommended Reading