This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes servlets with datadase interaction 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 "servlets with datadase interaction" Watch "servlets with datadase interaction" New topic
Author

servlets with datadase interaction

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
my question is what precautions i have to take while coding servlets which has data manipulation commands.
I have written a piece of code inside a doGet() method of a servlet.that code interacts with database ie. the code updates a record and insert a record.if thousands of people accessing the same servlent at the same time what will happen. will that servlet process all requests or will it throw an Exception.Do I have to take any care while writing this kind of code in a servlet.I want to avoid synchronization or synchronized block b'cos due to synchronization the servlet the servlet can't serve multiple clients at the same time.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
You will probably be all right. All modern databases support the concept of "transactions", groups of operations which mustn't be interrupted. As long as you make sure that all database operations which your servlet performs during a single request are grouped as a transaction, then the database should be able to handle many simultaneous accesses without getting confused.
For performance reasons, I would also recommend that you look into database connection pooling. If you continually have several servlets trying to access the database at once, you really don't want the overhead of opening a new connection for every request.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlets with datadase interaction
 
Similar Threads
Synchronization
Where do I need synchronization in Servlets?
2 frames/synchronization?
member variables in servlet
Synchronizing on the getServletContext() object