Hi Mike,

Because EJBs are pooled by the container, subsequent requests by different
clients may result in a previously created Bean being reused by another
client other than the one who originally contacted the Bean for the first
call (in the case of EntityBeans and StatelessSessionBeans... Not so for
StatefulSessionBeans) Each incoming call executes in its own Thread, but it
may not be a  _NEW_ thread.. It may be an instance of a pooled bean that has
already been created and already has a running ThreadContext.  (in your
PatternLayout add '%t' to the pattern and observe the Thread names that are
logged between invocations).  In this case anything that was previously
pushed into the Thread Context would still be there upon the next
invocation.  If you always overwrite everything in the MDC everytime, you
are probably safe. However, if you selectively add information based on some
logic, you run the risk of seeing MDC information from the previous clients
call. 

So to cover your bases it is safer to remove any MDC/NDC stuff you may have
pushed so that the context is clear for the next call (similar to the
technique when people make a Servlet Filter that intercepts HTTP
requests/responses and adds/removes MDC/NDC info before/after passing the
call to the next Filter in the chain) 


-d
-----Original Message-----
From: Lutz Michael [mailto:[EMAIL PROTECTED] 
Sent: Thursday, September 16, 2004 11:11 AM
To: 'Log4J Users List'
Subject: RE: MDC in J2EE


Thanks Don.

Pardon my ignorance, does the need to cleanup MDC stem from the fact that
threads in EJB's won't be cleared before moving on to the next request?  I'm
just trying to understand exactly why the MDC needs to be tore down.

Thanks again.
Mike

-----Original Message-----
From: Donald Larmee [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 16, 2004 10:33 AM
To: 'Log4J Users List'
Subject: RE: MDC in J2EE


Each EJB method invocation will execute within its own thread context.

For EJBs, you will want to push the MDC stuff into the Thread Context on a
method-call-by-method-call basis, and then remove it at the end of the
method in a finally block.  In that the EJB lifecycle model does not provide
a hook that is guaranteed to be executed upon every method invocation, this
is a necessary evil (however there are techniques that can be use to make it
less overt.. Like Spring AOP, jBoss interceptors, etc...) 

-d

-----Original Message-----
From: Lutz Michael [mailto:[EMAIL PROTECTED]
Sent: Wednesday, September 15, 2004 9:42 AM
To: 'Log4J Users List'
Subject: RE: MDC in J2EE


Thanks Yoav.
Mike

-----Original Message-----
From: Shapira, Yoav [mailto:[EMAIL PROTECTED]
Sent: Wednesday, September 15, 2004 9:27 AM
To: Log4J Users List
Subject: RE: MDC in J2EE



Hi,
If you're talking about the RequestDispatcher#forward method, the Servlet
Spec guarantees that it will execute on the same thread as the original
request (Servlet Spec v2.4, section SRV.8.2, it's unambiguous), so that's
what you're missing there.

For EJB calls, I don't know, you might be right.  I don't work with them as
much nowadays, so I don't remember the spec as well.

Yoav Shapira
Millennium Research Informatics


>-----Original Message-----
>From: Lutz Michael [mailto:[EMAIL PROTECTED]
>Sent: Wednesday, September 15, 2004 9:21 AM
>To: 'Log4J Users List'
>Subject: MDC in J2EE
>
>
>
>According to the J2EE spec there is no guarantee that a .forward
request or
>an EJB call will execute on the same thread (even if the EJB call lands
in
>the same process).  This seems to render MDC and NDC much less useful 
>because these constructs rely on the thread.  Changing it pulls the rug
out
>from under the mechanism.
>
>Am I missing something?  Is there a "standard" way Log4j users should 
>handle MDC to ensure the context persists across .forward and EJB calls 
>(when
in
>the same process)?
>
>I reviewed the Complete Manual and couldn't find anything related to
this
>question.
>
>Thanks for your time.
>
>Mike
>
>_______________________________________________
>Siemens Medical Solutions Health Services Michael Lutz Software 
>Engineer, Soarian Common Components
>51 Valley Stream Parkway, Malvern, PA 19355
>Office / Voice Mail    +01 610-219-8613
>Cell                   +01 610-952-2289
>Home Office            +01 610-989-3623
>Fax                    +01 610-219-4004
>E-mail <mailto:[EMAIL PROTECTED]>
>_______________________________________________
>
>
>-----------------------------------------------------------------------
----
>----
>This message and any included attachments are from Siemens Medical 
>Solutions USA, Inc. and are intended only for the addressee(s).
>The information contained herein may include trade secrets or
privileged or
>otherwise confidential information.  Unauthorized review, forwarding, 
>printing, copying, distributing, or using such information is strictly 
>prohibited
and
>may
>be unlawful.  If you received this message in error, or have reason to 
>believe you are not authorized to receive it, please promptly delete 
>this
message
>and
>notify the sender by e-mail with a copy to 
>[EMAIL PROTECTED]
>
>Thank you
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]




This e-mail, including any attachments, is a confidential business
communication, and may contain information that is confidential, proprietary
and/or privileged.  This e-mail is intended only for the individual(s) to
whom it is addressed, and may not be saved, copied, printed, disclosed or
used by anyone else.  If you are not the(an) intended recipient, please
immediately delete this e-mail from your computer system and notify the
sender.  Thank you.


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

----------------------------------------------------------------------------
---
This message and any included attachments are from Siemens Medical Solutions
USA, Inc. and are intended only for the addressee(s).  
The information contained herein may include trade secrets or privileged or
otherwise confidential information.  Unauthorized review, forwarding,
printing, copying, distributing, or using such information is strictly
prohibited and may be unlawful.  If you received this message in error, or
have reason to believe you are not authorized to receive it, please promptly
delete this message and notify the sender by e-mail with a copy to
[EMAIL PROTECTED] 

Thank you

---------------------------------------------------------------------
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]

----------------------------------------------------------------------------
---
This message and any included attachments are from Siemens Medical Solutions

USA, Inc. and are intended only for the addressee(s).  
The information contained herein may include trade secrets or privileged or 
otherwise confidential information.  Unauthorized review, forwarding,
printing, 
copying, distributing, or using such information is strictly prohibited and
may 
be unlawful.  If you received this message in error, or have reason to
believe 
you are not authorized to receive it, please promptly delete this message
and 
notify the sender by e-mail with a copy to
[EMAIL PROTECTED] 

Thank you

---------------------------------------------------------------------
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