• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Synchronized Blocks, Scope and Context?

 
Andrew Leer
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been reading here in my "Passing the Sun Certified Web Component Developer Exam" that inside a synchronized block is where you ought to put your access to the Session and your access to the ApplicationContext inside a servlet.

Now this would lead me to believe that since SpringMVC is also a servlet-based framework that you should also use a synchronized block when accessing (for just writes?) the user Session and the ApplicationContext.

Am I right about this?

Thank you,
Andrew J. Leer

P.S. (I'm guessing the same is true of any webframework that is servlet-based...like Struts for instance...)
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never heard of using a synchronized block for that... or at least I don't remember hearing anything like that.

Synchronized blocks are fairly expensive. I wouldn't resort to them unless I knew I had some ultra-critical reason for it. Even then I would heavily critique why I thought I needed it and try to figure out if what was needed could be done a better way.

With few exceptions, servlets shouldn't be setting anything into application scope. As for session scope, an issue would have to occur by two concurrent requests from the same session to justify the synch block - if your code creates a point of failure this way in dealing with session data, you're probably better off using tokens on your requests.
[ January 17, 2007: Message edited by: Marc Peabody ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic