EGL Development User Group

EGL Development User Group

EGL Development User Group

The EGL Development User Group is dedicated to sharing news, knowledge, and insights regarding the EGL language and Business Developer product. Consisting of IBMers, HCL, and users, this community collaborates to advance the EGL ecosystem.

 View Only
Expand all | Collapse all

Java Servlet Timer

  • 1.  Java Servlet Timer

    Posted Fri April 15, 2016 06:26 AM

    Hi,

    we have a Servlet with a timer which calls an EGL Program.

    The timer runs daily at 07:00 am.

    It works very fine.

    But if we restart the websphere application server e.g. at 01:00 pm the timer fires immediately again.

     

     

    package servlet;import java.text.ParseException;import java.util.Calendar;import java.util.Timer;import java.util.TimerTask;import javax.servlet.http.HttpServlet;import com.ibm.javart.JavartException;import com.ibm.javart.calls.PowerServer;import com.ibm.javart.calls.PowerServerImpl;public class InventurExportServlet extends HttpServlet {        private static final long serialVersionUID = -7218615493958066258L;        public InventurExportServlet() throws ParseException {                Timer timer = new Timer();                Task_INVENTUREXPORT task = new Task_INVENTUREXPORT();                Calendar today = Calendar.getInstance();                today.set(Calendar.HOUR_OF_DAY, 7);                today.set(Calendar.MINUTE, 20);                today.set(Calendar.SECOND, 0);                                 timer.schedule(task, today.getTime(), 43200000 * 2); // 24 Stunden        }}class Task_INVENTUREXPORT extends TimerTask {        public void run() {                PowerServer server = new PowerServerImpl();                try {                        InventurExportWrapper wrapper = new InventurExportWrapper(server);                        wrapper.call();                        server.commit();                        server.close();                } catch (JavartException je) {                        // handle error.                        je.printStackTrace();                } finally {                        try {                                if (server != null) {                                        server.close();                                }                        } catch (JavartException je) {                        }                }        }}

     

     

     

     

    Kind Regards.

     

    Marcel-D


  • 2.  Re: Java Servlet Timer

    Posted Fri April 15, 2016 06:36 AM

    The schedule function specifies the following:

    Schedules the specified task for execution at the specified time. If the time is in the past, the task is scheduled for immediate execution.

    If you restart at 1pm, you specify 7:20 am, which is in the past.

     

    It seems like it behaves as designed, and you will have to change your code to account for this.
     

    Bram_Callewaert


  • 3.  Re: Java Servlet Timer

    Posted Fri April 15, 2016 06:47 AM

    Hi Bram,

    thanks for your reply.

     

    we have already suspected that.

    Do you know how to change this?

     

    Thanks!

     

    Marcel-D


  • 4.  Re: Java Servlet Timer

    Posted Fri April 15, 2016 06:52 AM

    I would assume you check if the time of your today calendar is smaller than the current time, and if so add a day to your today calendar.

     

    Kind regards,

     

    Bram

    Bram_Callewaert


  • 5.  Re: Java Servlet Timer

    Posted Wed April 20, 2016 02:59 AM

    Thanks Bram!

    Marcel-D