Results 1 to 5 of 5
  1. #1
    javastuden's Avatar
    javastuden is offline Senior Member
    Join Date
    Nov 2009
    Posts
    160
    Rep Power
    5

    Default File is deleting when calling shutdown.bat

    HI All,
    In special situation i want a set of data that has to be store in a .ser file,means some values that has to store if tomcat is shutdown,and when tomcat restarted those values has to read from the file,so i use serialization of java and store the data at "tomcat_home\webapps\axis2\WEB-INF\classes"=='SaveValue.ser'.
    In my program i used
    static {
    Runtime.getRuntime().addShutdownHook(new Thread() {
    public void run() {
    System.out
    .println("---------------------Running Shutdown Hook-----------------------------");
    writeObjects();
    }
    });
    }
    the writeObjects() will do the serialization as described here Java Serialization | Java Beginner .
    if i click close button or press cntl-C while tomcat is running the SaveValue.ser will created and store in the location tomcat_home\webapps\axis2\WEB-INF\classes ,but when i click shutdown.bat the file is not creating .
    what is the problem how can do serilization with tomcat restart in axis2 webservice.please help me
    Thanks in advance

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    I'm not sure, but it could be tomcat is doing its own shutdown of the web applications before the java vm shutdown hook would be executed. If the objects that registered the shutdown hook get destroyed (all references to them lost) when the web applications are shut down normally when tomcat shutdown.bat runs stops tomcat normally, then its possible the shutdown hook would not be ran when the vm exits.

    In this case, would you be able to create a ServletContextListener in your web application that does the logic of the shutdown hook inside the contextDestroyed() method ? That will be ran when tomcat turns off the web application, such as on shutdown or application stop from the manager.

  3. #3
    lovelesh is offline Senior Member
    Join Date
    Nov 2010
    Location
    Delhi
    Posts
    135
    Blog Entries
    1
    Rep Power
    0

    Default

    Travishein is right.

    Shut down hooks are called only when jvm is shutdown properly.
    Looking at your problem suggests, tomcat doesn't do a proper shutdown of jvm. hence does not call shutdown hooks.

    You can try workaround suggested by Travishein.

  4. #4
    javastuden's Avatar
    javastuden is offline Senior Member
    Join Date
    Nov 2009
    Posts
    160
    Rep Power
    5

    Default

    hi,thanks for reply ,
    but i'm using axis2 webapplication means a service is created and that .aar file is just dumbed at \webapps\axis2\WEB-INF\services folder thats all.The servletcontext ,destroy methods are not taking in care by me so how can i resolve the problem.
    please tell me clearly
    please

  5. #5
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    hmm, so you are using the standard war release of axis2 ? For this we would need to customize the web.xml inside the axis2 web application to add a

    <listener class="package.to.you.custom.shutdownhook"/>

    and include this your custom shutdown class that implements ServletContextListener into the axis2 WEB-INF/classes folder.

    But now I am stumped, if the thread is initialized inside the .aar when it is deployed by axis2, I don't know how we would get a handle on the thread to have it stop from the servlet context listener. we would need some kind of .aar module lifecycle listener that axis2 would instruct to do stuff for us when it is starting up or shutting down a .aar module. I don't know what this is though.

Similar Threads

  1. Deleting '.zip' file...
    By vaibhavspawar in forum New To Java
    Replies: 2
    Last Post: 07-02-2010, 11:13 AM
  2. File Not Deleting
    By Moncleared in forum New To Java
    Replies: 7
    Last Post: 02-21-2010, 08:28 PM
  3. [SOLVED] deleting a line from a text file
    By mokonji in forum New To Java
    Replies: 0
    Last Post: 03-10-2009, 01:35 PM
  4. Help deleting a file
    By 3speed in forum New To Java
    Replies: 4
    Last Post: 11-01-2008, 05:27 AM
  5. Deleting a File that is opened
    By ravian in forum Advanced Java
    Replies: 6
    Last Post: 01-30-2008, 02:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •