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?
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.