Peter,

I'm a relatively new user of Log4j, but I think I can answer your question.

There is a separate NDC for each thread. The NDC has a Hashtable
of stacks keyed on Thread ID. When a thread accesses its stack (e.g.,
NDC.push), the NDC uses the Thread ID to find the right stack.

To answer your questions:

1) If you use a layout ConversionPattern to print your log messages, as
NumberCruncher does, the %x value in the pattern is replaced by the entire
NDC stack belonging to the thread. NDC.push() allows a method to add its
own context to logged messages. NDC.pop() allows the method to remove
its context when it is complete. NDC.remove() should be called to remove
the thread's stack before it exits.

2) The NDC has a static Hashtable. Each thread has its own stack in the
Hashtable
keyed by its Thread ID.

Hope this helps.

Regards,
Ernie Parker



|--------+------------------------->
|        |                         |
|--------+------------------------->
  >----------------------------------------------------------------------------|
  |                                                                            |
  >----------------------------------------------------------------------------|
|--------+------------------------->
|        |          Peter.Pan@comsa|
|        |          t.com          |
|        |          Phone not      |
|        |          available      |
|        |                         |
|        |          06/18/01 09:27 |
|        |          AM             |
|        |          Please respond |
|        |          to LOG4J Users |
|        |          Mailing List   |
|        |                         |
|--------+------------------------->
  >----------------------------------------------------------------------------|
  |                                                                            |
  |     To:     [EMAIL PROTECTED]                                  |
  |     cc:     (bcc: Ernie Parker/CHI/NTRS)                                   |
  |     Subject:      Confusing in NDC                                         |
  >----------------------------------------------------------------------------|




When log in multithread and other concurrent enviroment, NDC is used to push
something so that the logs can be distinguished. I am quite confused in the
follwoing points,

1. I see the sample program such as NumberCruncher only push something such as
localhost into the stack, but I do not see how those in stack finally are
written into the log files. Are they automatically written into the log files?
What is the relationn between category.info/debug/... and NDS.push()/pop()?

2. NDS have static interface functions. The stack it operated on should be
statich also. For multi-thread, the static member in class has seperate copy per
thread or they share still one copy?

Thanks,
Peter

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to