File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Variable Integrity---I'm scared!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Variable Integrity---I Watch "Variable Integrity---I New topic
Author

Variable Integrity---I'm scared!!!

jesse harris
Ranch Hand

Joined: Oct 02, 2000
Posts: 62
My understanding as servlets are concerned is that there is only one instantiation of a servlet at any given time, and that instantiation handles all the requests. This makes me very scared as the variables could be changed halfway thru execution by another incoming request. It is impossible for me to simulate the environment the servlet will be running in while I am testing, I cant send it many requests at once to check that the data integrity is intact. This seems like a fundamental question as servlets are concerned, but it is not mentioned in the books I have on servlet programming, am I totally lost or worrying needlessly about this? Any bones thrown my way are greatly appreciated.
Sean Casey
Ranch Hand

Joined: Dec 16, 2000
Posts: 625
If this is a major concern, you can always resort to synchronization, or the single thread model.
Andrew Shafer
Ranch Hand

Joined: Jan 19, 2001
Posts: 338

It all depends on the details but most of your concerns can be addressed with sessions.


!_I_Know_Kung_Fu_!
jesse harris
Ranch Hand

Joined: Oct 02, 2000
Posts: 62
As far as the synchronization or single thread model, would that not SERIOUSLY degrage performance due to overhead, and be a programming nightmare.
And as for the session, would you put the request/response in the session, and would that be the first line in the servlet, and also is it not possible that when the code is executing one request and putting it in a session, another request could come in and change the response before it was put in the session.
Or do you need to combine both approaches to optimize integrity, synchronize the code that puts the request/respose pair in the session which could be realistic, then just get them from the session when needed. But is that a fundamentally sound way to approach this problem, and would that stand up to 100-1000 concurrent connections.I'm still seaching for simplicity and elegance, but maybe its just not there.
Sean Casey
Ranch Hand

Joined: Dec 16, 2000
Posts: 625
Using the Single-Model Interface will hurt your performance. I believe all waiting requests get queued. Synchronization would probably be a better idea, making sure you only synchronize what is indeed important. I know I've read about this. I couldn't find it in O'Reilly's servlet book, but I did come across this in the Core Java Servlets and Java Server Pages:
page 154 near the bottom:
"Of, course the normal rules that require authors to synchronize multithreaded access to shared data still apply to servlets."
If I come across something else, I let you know.
- Sean
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Variable Integrity---I'm scared!!!
 
Similar Threads
2 frames/synchronization?
Why we live?
JavaBeans in Model 2
Implementing multi-tire application and persistent DB connection in WebLogic
changing http get request to post request