2

When a user sends a request to my web application, a user session id is added to the NDC stack to be used in the log4j log files, but for some reason, when I call another method, the session id doesn't seem to be in the log calls within that method. Though once that method has completed the rest of the process, still retains the session id within the log files.

I'm not too sure why this is happening and was wondering if anyone knows of why this may be or has any theories on the reason for loosing the session id?

Thanks for any help given.

user3399000
  • 353
  • 3
  • 18
sbnarra
  • 556
  • 4
  • 9
  • 25

1 Answers1

2

NDCs are managed on a per-thread basis - that means that if you push the session ID onto the stack in one thread and then call a method in another thread your session ID won't be present.

It's hard for me to answer without the context of your code... If you post your code I could probably provide a specific answer.

Mike Gillan
  • 384
  • 2
  • 8
  • 1
    Hi, Sorry forgot to update this question with the answer. The method being called was kicking off a new thread. I managed to maintain the session id by passing it through to the constructor of the class that was starting the new thread by using NDC.peek() – sbnarra Apr 11 '13 at 22:31