• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

synchronized(session) will really help...?????

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends...

in page no. 200 HFS it is said that.. synchronized(session);
will help.. us for making consistent

but small doubt... is here we have done this session synchronize

but problem is that..
when the user opens a new browser and.. he ask for, then this will consider in the same session...

so if the user opens.. 3 web broser pages and.. try to manipulate the values..

no one can stop him despite of.. make "session synchronize"

if i am wrong in this concept please help me to rectify.. and explain me...as i am new...

Thank you very much
bye,.......
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The problem is that different requests (from different browsers on the same machine, or different machines) are handled by the container as
different THREADS
acting upon a single INSTANCE of the servlet.

So, these different threads could concurrently access the session, and you could get results that you weren't expecting.

Synchronizing on the session means that whenever a thread wants to access the session, it must first access the session object's lock. There is only a single lock, so only one thread can access the session at once. This protects the session (and you) from getting results you weren't expecting from threads concurrently accessing the session.

The downside of course, is that while one thread has the lock, all other threads are blocked, so synchronizing for long periods of time could be bad for performance. I think HFSJ gives the advice to "get in, do whatever you need and get out".

Hope that helps,
 
kajal mukergi
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark

Thank you very much now i got the complete idea on it..

thanks
bye..
 
them good ole boys were drinking whiskey and rye singin' this'll be the day that I die. Drink tiny ad.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic