java - MemoryHandler not Pushing when application terminates -


i writing java server application using java.util.logging, memoryhandler.

how make memoryhandler push data out file when application terminates?

i tried add shutdownhook , manually push data file, appears log handlers removed when reaching "hook".

this code:

public class example implements runnable{ static {     // set upp logging     // adding memoryhandler     filehandler filehandler = null;     memoryhandler memoryhandler;      try {         filehandler = new filehandler("myapp.log");         filehandler.setlevel(level.all);     } catch (ioexception e) {         e.printstacktrace();     }      memoryhandler = new memoryhandler( filehandler, 100, level.severe);     logger rootlogger = logger.getlogger("");     rootlogger.addhandler(memoryhandler); }   public static void main(string[] args) throws exception {          thread serverthread = new thread(new example());         serverthread.setdaemon(false);         serverthread.start(); }  public void run() {      runtime.getruntime().addshutdownhook(new thread() {         @override         public void run() {             // execute when application shutting down.             //             // memoryhandler not not in handlers list             (handler handler: logger.getlogger("").gethandlers())             {                 system.out.println("looping handlers");                 if (handler.getclass() == memoryhandler.class)                 {                    system.out.println("memoryhandler found");                    //this never happens.                    ((memoryhandler)handler).push();                 }          }     });      try {         // alot of stuff     }     catch (exception ex)     {     }  } } 

please advice!


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -