This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques and have Mario Casciaro & Luciano Mammino on-line!
See this thread for details.
Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark

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

thanks
bye..
 
You showed up just in time for the waffles! And this 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
reply
    Bookmark Topic Watch Topic
  • New Topic