• 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:

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: 4116
72
Mac TypeScript Chrome Java Linux
  • 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: 608
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.
 
See where your hand is? Not there. It's next to this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic