This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am trying to set up code such that when an exception occurs, my custom handler is called which calls a logging class which logs the exception, along with the calling IP [request.getRemoteAddr()]. I thought it would be best to make the logger class static so it could be called easily from anywhere (as opposed to passing an instantiated object into every class I use). They way I have it coded now, when I initialize the static logger class I pass the calling IP so the logger has that additional information and can write it to the log file. However, I realized this is a bug since that logger class's static variables will be global across all users, in other words if more than person hits the page at a time there will be problems. I thought that I might need to use S = request.getSession() to store session-scoped variables, but then I have the problem of passing S around to every class that I use in order to get this info. Does anyone know a good way to do this? I was thinking the best way would be to have a function GetSessionInfo('remoteaddr'), which I can call from anywhere, sort of a session-global variable. I'm relatively green to Java, so maybe I'm thinking about this the wrong way... Thanks alot! [ April 20, 2004: Message edited by: jeff wisgo ]
I think you are. The purpose of context variables is precisely to contain thread-safe context on behalf of the processing thread. Not wanting to "pass them around" ignores their purpose. That said, I'd also revisit the decision to make the handler static to begin with. I think that shows that you are not "thinking in Java".