• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpSessionListener in HFSJ page 259

 
osman cinar eren
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i would like to ask a question on the example on page 259 of HFSJ. There is a private static counter variable which is incremented in sessionCreated() and decremented in sessionDestroyed(). These operations are NOT atomic, i guess. So these operations must be synchronized in order to work correct. What are your opinions? Am I right?

thanks in advance.
best regards..
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thread safe code always runs slower, so we need to think hard and twice before using it to achieve the correct results

If the number of users is small and the traffic low, I wouldn't bother.
else might synchronize the block manipulating the increment/decrement of the counter.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic