Menu

Couple of fixes - container shutdown, emails

2002-07-19
2002-08-31
  • NSL Developer 2

    NSL Developer 2 - 2002-07-19

    Hello, we encountered a couple of issues and fixed them.  If it would help to have these fixes, please let me know (although source sync might pose a problem!)

    Regards,
    Keith

    Running environment:
    ~~~~~~~~~~~~~~~~~~~~

    VM:                      Sun JDK1.4.0
    Container:               Tomcat 4.0.2

    Development platform(s): Win32 (XP Pro)
    Tested on:               NT4 (SP3), XP Pro
    Tests pending for:       Solaris 2.6

    Issues:
    ~~~~~~~

    1. Temination of application slow. 
       Observation: At times, caused container to wait till application terminated.

       Comments:    Even after the container had called "destroy" for all servlets,
                    jcrontab did not complete all threads causing container to wait.
                    The destroy method of the servlet 'loadCrontabServlet' is called
                    and then the application waits for threads to join.  This code
                    is seen in org.jcrontab.Crontab.unint(..)

       Fixes:       1) Servlet 'destroy' method added to org.jcrontab.loadCrontabServlet.
                       This simply calls the unint method of Crontab.  The shutdown
                       hook is still left as is to ensure 100% cleanup is achieved
                       but would not necessarily do anything useful now.

                    2) Crontab.unint(..) modified to make sure waiting threads are
                       interrupted.  Each task (org.jcrontab.CronTask) is interrupted
                       before the calling join(..).
                       Once all tasks are "joined" with, the actual cron scheduler
                       (org.jcrontab.Cron) is interrupted as well in case it is
                       sleeping/waiting to generate cron events.
                       The above interrupting of threads ensures that joining times
                       are minimised.  Downside is that any running tasks could well
                       be interrupted in the middle and cleanup/wrap-up may not be
                       acheived.

                    3) Modified methods waitNextMinute() and generateEvents()
                       of org.jcrontab.Cron.  Both methods now check whether they
                       thread needs to be run or not.  This is already determined by
                       shouldRun field (private field).  Therefore Cron now makes
                       sure that if the entire application needs termination, it
                       does not generate any events (which now make no sense to do
                       as everything is coming to an end) or wait for any longer
                       time (as it makes sense for everything to finish up as soon
                       as possible as the container/application is dying).

       Status:      Fixed requirement.

       Todo:        a) Investigate is wrap ups, etc of running tasks can be adversely
                       affected in CronTask.

    2. Emailing of a process report is buggy.
       Observation: A) Once an email is sent for the first time, any output to the console
                       goes away.
                    B) Path for temp file creation not correct
                    C) Temp files created are not cleaned up
                    D) Output generated outside a given process ends up in an email
                    E) Process errors (written to err stream) not in email
                    F) Sending mail fails as cannot get properties

       Comments:    i) PrintStream redirection/cleaup issues are the cause.
                    ii) Path for the temp files within application or container not
                        either specified or not right
                    iii) Perhaps temp file not closed that could lead to problems as well?

       Fixes:       1) Issue 2.B was solved by finding out the path which was expected.
                       This turned out to be by default "temp" directory sitting off
                       the container's root dir.  This will be platform dependent more
                       than likely.  On NT/XP, fixed by creating a folder "temp" sitting
                       off the container's home.  Note: This temp dir can also be
                       specified in the container's config.
                    2) Issues A, C, D and E were solved by doing the following in the
                       run() method of org.jcrontab.CronTask:
                       - storing away the original out and err streams so that upon
                         completion of the task at hand, they can be restored;
                       - Out and Err streams are directed to the temp file;
                       - Closing the temp file (java.io.FileOutputStream.close method);
                       - Restoring out and err streams to the original ones.  A finally
                         block is added that also does this in case an exception was
                         raised somewhere else.
                    3) Issue F fixed by a simple case of ensuring correct character
                       capitalisation in the code.  Now looks for org.jcrontab.SendMail.from
                       rather than org.jcrontab.sendMail.from to follow with other
                       property naming conventions in the properties file.

       Status:      Fixed bugs.

       Todo:        Document in (1) the config param that can be set to ensure temp dir
                    problems cannot occur.

    Suggestions
    ~~~~~~~~~~~

    1) Rather that config files, etc being in org.jcrontab.data folder, why not keep them
       in WEB-INF/etc.  For UNIX based people, this would be the first place they'll look.

       Status: Done.  Application (servlet) config in web.xml specifies required directory.

     
    • Manpreet Singh

      Manpreet Singh - 2002-07-19

      Hi, I would like the fixes you made. A patch would be preferable but you could email just the affected source files too. Much appreciated.

      Thanks
      Manpreet

       
    • NSL Developer 2

      NSL Developer 2 - 2002-07-23

      I will do as soon as we have taken out debug messages. 

      If you want it sooner and don't mind the messy output it currently produces, then just let me know -- I'll be able to furnish the source files in that case.

      - Ashish

       
    • Israel Olalla

      Israel Olalla - 2002-07-26

      Hi,
         I recommend sending the patches or whatever other  improvement to jcrontab-developers@lists.sourceforge.net , in this list will get more attention.
        
         If you send patches, code or any other thing like this will be readed and surely added to jcrontab core.

      sorry for the delay in the answer but have tons of work  :-)

       
    • Israel Olalla

      Israel Olalla - 2002-08-31

      I've fixed what you said in point 1... it was bug 600127 :-)

       

Log in to post a comment.

MongoDB Logo MongoDB