I've been learning java on and off for about a year now and while I've covered a lot of ground and built a few small applications successfully, I'm still confused about one simple thing - the scope of global variables in a servlet.
A servlet being multi-threaded, wouldn't global variables in a servlet be unsafe to rely on from request-to-request? For example, an object stored globally could change between two users and the data wouldn't be reliable, is that correct? What about a Hibernate session, as another example? Couldn't the session be closed in one thread invalidating another user's request to that session in another thread?
I was reading this article about optimizing servlets/jsp for performance: