Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2005

Tip: Looking for answers? Try searching our database.

lib of static class methods, java logging

Thread view: 
frank - 14 Jul 2005 13:05 GMT
Was wondering what might be the better way to do something in java. I
have a class of static methods that are a library and I want to use the
java.  To do that I need to use the log variable I have setup already.
What is the best way to initialize and use that in the methods?

1. Create an instance variable in the static class lib for log and do a
new on the thing when  start my program

_util = new JBFSAUtility(logger);
...

  static Logger logger;

  JBFSAUtility(Logger l)
  {
      logger = l;
  }
.....

2. Pass the log variable to each method?

JBFSAUtility.method1(Logger l);

Thanks,

Frank
Boudewijn Dijkstra - 14 Jul 2005 16:55 GMT
> Was wondering what might be the better way to do something in java. I have a
> class of static methods that are a library and I want to use the java.  To
[quoted text clipped - 14 lines]
>   }
> .....

This code will overwrite static member logger everytime a new object is
created.  If class JBFSAUtility should use the same logger in the entire VM,
then keep it static and don't use a constructor at all.  Otherwise, don't make
logger static, and use JBFSAUtility objects.

> 2. Pass the log variable to each method?
>
> JBFSAUtility.method1(Logger l);

This code is even less sensible from a object-oriented point of view...
Hemal  Pandya - 14 Jul 2005 17:23 GMT
>    static Logger logger;
>
>    JBFSAUtility(Logger l)
>    {
>        logger = l;
>    }

In the interest of symmetry consider providing a static method
setLogger in JBFSAUtility. You would still have to worry about some
other method of the class getting called before the setLogger is
called, but that problem you have to tackle even with the current
approach.

So the call

_util = new JBFSAUtility(logger);

changes to

JBFSAUtility.setLogger(logger);


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.