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..
posted 12 years ago
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.