This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi, I am using MVC pattern in my web application, I have a question regarding using context to store my dataoperation object(which handles all the data base related operations). What essentially I am doing is calling my action class from Controller Servlet this action class then uses dataoperation class to perform db calls. For sake of simplicity I have stored dataoperations in servlet context and all my action classes uses the servletcontext to obtain handle to data operations. I want to know whether this is the correct approach or should I use session scope to store an instance of Dataoperation. Or is there any other way to do it. Hope I made myself clear. Regards, Vijay
First, you must synchronize the data operations to guarantee data integrity. Even though, the dataoperation object still may become the bottle neck of the whole web application. Especially when many requests compete for that object. Putting it into session is more scalable. Hope it helps. Dan
If your "data operations" use a connection pool (JDBC DataSource) and don't use any member variables, you're okay. No need to synchronize it at all. Should work out just fine and would be just as scalable as storing it in the session. Remember that sessions CAN be accessed by two different threads at the same time!
James Carman, President<br />Carman Consulting, Inc.
Joined: Jul 30, 2001
Jammy, Danny thanks for your reply. Well I am using connection pooling and not using any member varaibles, so I hope this will work out all fine. Cheers, Vijay