As long as you don't mark the logger variable in class X as static, the solution I suggested earlier should work like a charm.


At 11:10 PM 6/11/2004, you wrote:
Sorry, in an earlier java prototype we had problems with static objects.
There were two applications that use separate loggers. Everything worked
well because they were in their own JVM. When they were combined into one
JVM, the first one to be invoked got the static object and both then wrote
to that one. Which is one of the reason we moved to log4j to do logging.
So it was on my mind when I was thinking how the multiple servlets using the
threadLocal idea would work. I should not have asked since now that I thought
about it some more, it should not be a problem.

Just finished trying out the chainsaw idea. On to learning more about
localThreads (as you suspected).

-----Original Message-----
From: Ceki Gülcü [mailto:[EMAIL PROTECTED]
Sent: Friday, June 11, 2004 4:49 PM
To: Log4J Users List
Subject: RE: Separate log file per servlet



At 10:38 PM 6/11/2004, you wrote:
>What about static objects in the JVM? Would each
>Servlet get their own instance of X or will it get
>the static one?

What do you mean by static objects in the JVM

>If the Servlet spawned off threads? Then it should
>still work because you have not changed the TL.
>
>Does that sound right? I was just trying to mentally
>think what will happen when servlet 2 comes up.
>
>    servlet1 sets the TL to "servlet1"
>    servlet 1 creates an instance of X, say x1
>    while constructing x1, x1 reads TL, the read value is "servlet1"
>    the constructor retrieves a logger whose name depends on the value of TL
>    servlet 1 calls a method on x1, say foo()
>    x1.foo() logs with that logger specific to the x1
>
>    servlet2 sets its TL to "servlet2"
>    servlet2 creates an instance of X, say x2
>    while constructing x2, x2 reads TL, the read value is "servlet2"
>    the constructor retrieves a logger whose name depends on the value of TL
>    servlet2 calls a method on x2, say foo()
>    x2.foo() logs with the logger specific to the x2
>
>    x1.foo() eventually returns
>    servlet1 eventually returns, before returning it sets TL to null
>
>    x2.foo() eventually returns
>    servlet2 eventually returns, before returning it sets TL to null


Are you familiar with thread local variables? If not, invest a few minutes to experiment.

http://java.sun.com/j2se/1.3/docs/api/java/lang/ThreadLocal.html




-- Ceki Gülcü

      For log4j documentation consider "The complete log4j manual"
      ISBN: 2970036908 http://www.qos.ch/shop/products/clm_t.jsp



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

-- Ceki Gülcü

For log4j documentation consider "The complete log4j manual"
ISBN: 2970036908 http://www.qos.ch/shop/products/clm_t.jsp




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



Reply via email to