Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

storing object in servletcontext

 
Vijay Kashyap
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
danny liu
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Vijay Kashyap
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic