This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Timer Process

 
vjy chin
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
vjy chin
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
vjy chin
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ben,

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

Thanks for the URL.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic