Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

why need to synchronize the context and session attributes ?

 
Ranch Hand
Posts: 69
Mac OS X Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
->when we synchronize the context or session attributes , the only one thread can access it...
so it means that we are indirectly making the single thread model,
some body told me to not use single thread model.somebody please explain
the disadvantage of single thread model also...

 
Bartender
Posts: 4109
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Synchronizing session, context objects means making any shared and modifiable data within them thread safe. That should be done very carefully to minimize the overhead. But the other methods (assuming synchronizing on a block inside the method) of the servlet instance is accessible to other threads. On the other hand the single thread model make the entire servlet instance dedicated to only one thread at a time. But even with that it's not possible to protect static members of the servlet instance or any other uses of context, session attributes without explicit synchronization. That's why it's deprecated as it doesn't give any good for the developer.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

synchronize the context or session attributes



That statement shows how using incorrect language leads to errors.

If synchronization is necessary, you synchronize only on the access to attributes, as soon as the retrieval or modification is done, which should take very few CPU cycles, synchronization is dropped.

Bill
 
Ranch Hand
Posts: 300
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
synchronization is very costly and affect the performance so make sure what you need to synchronize and as said minimize it as much as possible.
 
Ranch Hand
Posts: 607
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Javin Paul wrote:synchronization is very costly and affect the performance so make sure what you need to synchronize and as said minimize it as much as possible.



I don't think synchronization by itself is very costly in never versions of the JDK/JRE. However it does restrict what can process in parallel and so yes you do need to make sure synchronization is minimal as possible.
 
Check your pockets for water buffalo. You might need to use this tiny ad until locate a water buffalo:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic