• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Synchronized Blocks, Scope and Context?

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...)
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
What kind of corn soldier are you? And don't say "kernel" - that's only for this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic