aspose file tools*
The moose likes Servlets and the fly likes Job Schedular in Java/Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Job Schedular in Java/Servlets" Watch "Job Schedular in Java/Servlets" New topic
Author

Job Schedular in Java/Servlets

vivek Jain s
Greenhorn

Joined: Nov 23, 2010
Posts: 3
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

Joined: Oct 09, 2008
Posts: 92

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.


http://serfj.sourceforge.net - Simplest Ever REST Framework for Java
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

something like Quartz might be an option.


Beat me to it ! ++ on Quartz


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
vivek Jain s
Greenhorn

Joined: Nov 23, 2010
Posts: 3
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

Joined: Feb 24, 2006
Posts: 6662
    
    5

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

Joined: Jun 25, 2001
Posts: 16303
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Job Schedular in Java/Servlets