logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Graham Mead" <graham.m...@uk.royalsun.com>
Subject NDC , Servlets and thread safety
Date Wed, 06 Nov 2002 16:23:52 GMT


This may have been asked before but I cant find it in the archives. I am
trying to use the log4j NDC class to log and distinguish between multiple
client requests coming into a single servlet instance (we are using the
frontcontroller pattern). We issue a NDC.push() at the start of the doPost
method passing in the session ID and a NDC.pop() at the end of the doPost()

As the servlet operates in the same thread and doPost() is not synchronized
isn't it quite possible that two users could get into the same method and
effectively push() two lots of information into the NDC so that the output
from log4j contains session ids from BOTH of the clients.

Apologies if I'm being stupid but if this is a problem has anyone
encountered this before and have an elegant solution?

By the way we don't really want to make the servlet implement the
SingleThreadModel or synchronize the doGet, doPost methods as we believe
this would kill the application.

Thanks in advance of any comments

Graham Mead

To unsubscribe, e-mail:   <mailto:log4j-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:log4j-user-help@jakarta.apache.org>

View raw message