aspose file tools*
The moose likes Servlets and the fly likes Timer Process Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Timer Process" Watch "Timer Process" New topic
Author

Timer Process

vjy chin
Ranch Hand

Joined: Feb 17, 2005
Posts: 279
Hi,
I apologize if this is not the right thread, and the moderators may move it to the exact one.

My problem is - I need to process a java function everyday. i.e the function should run everyday without any user commands.

I have devised a simple servlet, giving a value 1 on load-on-startup tag in the web.xml. I am calling the timer function from the init method of the servlet.

the code is:




Actually the task is to connect to the database and retreive some results, then perform some operations and insert new records in the database based on the results. I need this to run everyday.

Is there any problem using this solution, since one of my collegue told me that Timer may not work properly in j2ee environment. He asked me to use ejb.timers.

Any help on this is much appreciated.

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61202
    
  66

A servlet, designed to respond to a user request and to return a response, is a spectacularly poor choice for this type of operation.

Why not just write a simple Java program that will perform this operation and use whatever scheduling mechanism is appropriate for your OS (cron, for example) to kick it off at appropriate times?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
vjy chin
Ranch Hand

Joined: Feb 17, 2005
Posts: 279
Thanks for the reply.

Actually I dont want to use the OS scheduler, that would be my las option (I was told so, since development and production are different OS's). So is there any other way I can do this.

Moreover, it would be of great help if you can point me where I can find tutorials for scheduling a java program using windows scheduler.

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61202
    
  66

Originally posted by vjy chin:

since development and production are different OS's


I don't see how that makes any difference.

Moreover, it would be of great help if you can point me where I can find tutorials for scheduling a java program using windows scheduler.


Sorry, can't help you there. I avoid Windows as much as I can. I believe that there have been other topics on this subject that may help you out there. And there's always google...
vjy chin
Ranch Hand

Joined: Feb 17, 2005
Posts: 279
Thanks for the reply.

I don't see how that makes any difference


Since I will not be able to test in Linux, as I dont have access to the box.

I will search for the schedulers.

Thanks.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Take a look at Quartz.
Not sure of the URL.

You can build your timer in a plain old java object (POJO) and instanciate it from a ServletContextListener.

As Bear mentioned, it's much easier to use the OS's scheduler.
When calling Java programs from the Windows scheduler, I just wrap the Java program with a small batch script and call that script from the a scheduled task.

On Unix, the combination of wget and cron make this a one liner.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

See:
http://www.onjava.com/pub/a/onjava/2004/03/10/quartz.html
vjy chin
Ranch Hand

Joined: Feb 17, 2005
Posts: 279
Thanks Ben,

I will look into it and will let you know which one was used.

Thanks for the URL.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Timer Process