learner
learner

Reputation: 1155

Java: (Threads/Timer) Run a function everyday at say 6AM

I have my application on Windows platform and want a java function to be executed everyday at some particular period of time. Need some guidance how to go about it. Have already looked for some previous posts but need some understanding of which method to use and how?

Thanks.

Upvotes: 2

Views: 616

Answers (4)

sikas
sikas

Reputation: 5523

Since you are using JSP and having your own server, you might set it as a scheduled task (Windows) to run at 6AM Everyday

First this is called Cron Jobs

Go to the Task Scheduler Win 7: Start -> All Programs -> Accessories -> System Tools -> Task Scheduler

From the right panel choose "Create Basic Task ..."

Give the task a name, hit next.

In the trigger tab, choose daily, then click next.

The next tab will let you set the specified date to start launching the trigger, the time, set the time and hit next.

In the Action tab, choose "Start A Program", then Next/.

In the next tab, click browse next to the program/script field, then navigate to the location of the Apache tomcat Server and choose the application.

(for the appache from WAMP Package: wamp\bin\apache\Apache2.2.11\bin\httpd.exe) tom cat will difer a bit I guess.

hit Next then Check the "Open the Properties Dialog for this task when I click Finish" then click Finish.

Now go to the action tab, select the first and only action available, click edit.

in the program/script field and modify type a space, then URL

change the URL to the URL you use to access your page.

This will let you be able to launch the script everyday at 6AM.

Upvotes: -1

Ercan
Ercan

Reputation: 2773

I made the same process in C#.

-First Create table that includes time table that when you want to run your function - Get time from table and calculate interval like after checking adding +1 day or 24 hours to your time which you get from table.

I made it for schedule in university.I used dayname,date,time.Like this you can control also which day ,which time will run your function

Upvotes: 0

Lie Ryan
Lie Ryan

Reputation: 64847

If you're on Windows, use scheduled task

If you're on Linux/Unix, use cron

Upvotes: 4

Brian Agnew
Brian Agnew

Reputation: 272277

You may find Quartz of use. It's a Java framework which provides the ability to invoke tasks at particular intervals, at particular times of day etc.

So you can invoke Tomcat and the Quartz framework - built into your app and suitably configured - can invoke methods at particular intervals/times of day.

Upvotes: 4

Related Questions