Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Logger / ShutdownHook

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have created a Logger,

In using this log in ALL my methods the log.entering("...") and log.exiting("..."); work as expected until a get to a close method in which case nothing is logged. I call setUpHook() in the constructor of the class.

What am I missing?
 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

read carefully this:
http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/api/java/lang/Runtime.html#addShutdownHook%28java.lang.Thread%29

Shutdown hooks .... should also not rely blindly upon services that may have registered their own shutdown hooks and therefore may themselves in the process of shutting down.



then check source code of LogManager here:
http://kickjava.com/src/java/util/logging/LogManager.java.htm

line 224:


Evidently LogManager registers it's own shutdown hook.
JVM runs shutdown hooks in randomly order, and probably LogManager's hook is called before your program's hook,
and logging subsystem has been probably closed when your program tries to write event log in close() method.
 
Roy Pozarelli
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've read over the source code for LogManager that you referenced and in particular the protected default constructor that adds the a shutdown hook for a new Cleaner() and the comment about if we are already shutting down then we don't have to register the shutdown hook. So in thinking about this I changed from using a static private Logger log = ... to the following:


So that I was creating a new log while in shutdown. The program now seems to work as expected and is consistent. Am I correct in thinking that because this new log was not "registered" it will not be interfered with by the LogManager's thread. Or do I still have potential conflicting issues?
 
Roy Pozarelli
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just read the real solution, to make it an anonymous logger - these are not registered with the LogManager and hence a clean of any interference.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic