• 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

servlets with datadase interaction

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic