The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
October 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Thread Safety

Posted by Grog on October 04, 2001 at 4:46 PM

I have a scenario where I have written a class which wraps a logger component. I create an instance of the logger component within my class, holding this within a private variable and have then written some public methods which allow multiple servlets to send various levels of logging. At the moment I have not synchronised any of the methods I have made available and am aware that if these were accessing a data variable such as an int, this would not be thread safe. Is this the same case for a reference to a component, to which I am just passing Strings to several of its methods? Code is as follows:

class LogWrapper
{
private Logger _log =new Logger(); //ref to logger component

public void logError(String s)
{
_log.error(s);
}
public void logWarning(String s)
{
_log.warning(s);
}
}

PS: The reason I have done what seems a pointless wrap is as this is run within a Weblogic Server and I add several Weblogic interfaces which allow auto creation of the class on Web Server start-up.



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us