On 31 Aug 2004 15:43:29 +0800, Sebastian Ho
<[EMAIL PROTECTED]> wrote:
> Hi
> 
> I am in the stage of implementing logging in my struts application. I
> have been reading online but have some questions unanswered.
> 
> 1. Action class should be thread-safe. Therefore no static variable, I
> should just use a non-static variable to hold my logger?
> 

A more precise definition of the rule is "no non-thread-safe static or
instance variables that attempt to maintain state associated with a
particlar request."  Log instances are OK based on that rule, because
they are both threadsafe and application-wide.

> 2. In a multi-user web application, how can I keep logs from the same
> class (same execution thread or same user request) stays together? I
> envision them to be all messy in the log file when there's multiple user
> requesting for the same action class.

As Nico points out, you can get the thread id added, that doesn't help
segregate log messages by application.  A different strategy is to set
up a separate logging environment for each webapp -- details will be
in, for example, the Log4J information.

> 3. About the thread safe issue with Actin class, that doesn't apply to
> the other classes that action execute right? Those are treated as normal
> java files.

Thread safety of the object instances you call depends on whether you
created a separate instance for each request, or are reusing the same
instance.  In the former case, you don't have to worry -- in the
latter case (say you grabbed some common utility object out of the
application scope attributes), then the class for the instance you are
calling does need to be worried about thread safety.

> 
> Thanks
> 
> Sebastian
> 

Craig

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

Reply via email to