• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Job Schedular in Java/Servlets

 
vivek Jain s
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

In my application, I need to update the database tables at regular intervals according to logic.

I have written a Java program for this. And my need is to run this Java program every night at 11 PM.

In a Nutshell, I have to schedule a job to execute on regular basis. One of my friend suggested me that the same can be done through web.xml file.

I am not aware about it. Please suggest.

Regds
Vivek
 
Eduardo YaƱez Parareda
Ranch Hand
Posts: 93
IntelliJ IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best choice is calling your program from a shell script then configure your cron to run it at 11PM, that way you don't need any application server running.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another choice, if your server is up 24/7, is a Timer and TimerTask. If you need a really rich API, something like Quartz might be an option.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
something like Quartz might be an option.


Beat me to it ! ++ on Quartz
 
vivek Jain s
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:Another choice, if your server is up 24/7, is a Timer and TimerTask. If you need a really rich API, Quartz might be an option.


Thanks Paul !! I dont need rich API. A Java file needs to be executed at a particular time in a day. That's it. My queries :

- Even for this, will I have to use this Timer and TimerTask ?
- Is it possible through web.xml, anyhow with simple tags?

Thanks !!
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible through web.xml, anyhow with simple tags?


It is not. Timer and TimerTask are as simple as it gets
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17645
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The optimal solution to this question depends in part on how much work the scheduled task will do.

One thing that is often overlooked when putting heavy-duty batch logic into web applications is that long-running processes can hold the entire appserver hostage, since if an emergency arises and the appserver needs to be restarted (or even just scheduled maintenance), you have to choose between killing the batch process or waiting for it to complete.

In any event, DON'T spawn the batch process thread from a web HTTP request. Do it in a servlet's init() method. Request processors, per the J2EE spec are forbidden from spawning threads. And with good reason, since the parent thread is going back into the pool and if a subsequent request scheduled under that thread fails, it will end up killing the batch thread as well. Or, at a minimum, you're violated the idea that one pool thread is as good as any other pool thread. The Quartz scheduler is also good here, as it has its own resources, and doesn't depend on the HTTP thread pool.

About the simplest way to run a process on schedule is to use the language Timer resources, but if the exact launch time is critical, some care needs to be observed on how the next request is scheduled or the actual start time may drift.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic