This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
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.
It all depends on the details but most of your concerns can be addressed with sessions.
Joined: Oct 02, 2000
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.
Joined: Dec 16, 2000
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