• 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

Prevention of Data Corruption in Servlets?

 
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to know how can we prevent data corruptionn in servlets in real time scenarios. For example i have a servlet, and it may handle mulitple requests through multiple threads, so how can i prevent data corruption. May be through synchronization of doGet() method, but then there are limitaions with it, also Single thhread model do have limitations. So could any one tell me how to handle such scennarios? Any API is available?
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What type of data corruption are you talking about??
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you actually *have* any data corruption?
 
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What data are you talking about?

If you have instance variables in the servlet, they will be shared across all requests, so you will want to synchronize your access to them. However, if you keep your state information in the session, then each client/session will have their own copy. You can still run into trouble if the same client makes two simultaneous requests (say from two separate browser windows), but this isn't as likely.

Chapter 3 (Servlet Basics) of the book Core Servlets and JavaServer Pages, which is available in PDF format here: http://pdf.coreservlets.com/Servlet-Basics.pdf goes into details about the pitfalls of using the SingleThreadModel interface and how and when to properly synchronize your code.

Best Regards,
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic