[logback-user] Question about MDC in servlet init() method

Stefan Frings stefan at meinemullemaus.de
Sat Mar 1 21:34:29 CET 2008


Lets assume I call MDC.put("applicationName","whatever") in the
servlet init() method. Can I read this later in the service()

I'm asking because some weeks ago I noticed that this did not work.
I assumed that the threads running service() are not childrens of
the thread that runs init().

However, I tried this again today, and this time it worked fine. I
was not able to reproduce the problem.

But before I do such things now in real web applications, I like to
be sure if thats Ok.

Can I set MDC variables in init() and read them in service() safely,
or does this work only randomly or under special conditions?

More information about the Logback-user mailing list