This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
I keep having some trouble understanding synchronizing concept in the context of static vs nonstatic. For e.g. take a look at the code below:
It is a simple listener that counts number of active sessions. However, we know HttpSession object is not thread safe. So I believe that "counter" variable should be incremented in a "synchronized" manner.
It is clear that getCounter() should change to public synchronized static int getSessionCounter()
My question is what changes should be implemented in sessionDestroyed() and sessionCreated() methods? Which of the following is correct?