File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Linux / UNIX and the fly likes run a Java application every hour automatically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "run a Java application every hour automatically" Watch "run a Java application every hour automatically" New topic

run a Java application every hour automatically

sarah Marsh
Ranch Hand

Joined: Mar 06, 2001
Posts: 282
Hello all:
I need to run a Java application every hour
automatically. How to do it under Bourne/Korn
shell? Please point some books or website that
I can take a look if I have to write some
shell scripts or through some other ways.
Thanks in advance,
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

This is just an idea versus an answer for you. The way I would do it is write a C program that stays in an infinite while() loop. In the while loop you would create a new PThread in unix and execute the java application. Also, you would want to check for when that program has termintated and kill that PThread. Then, you can just set a timer, and do it every hour that way.

GenRocket - Experts at Building Test Data
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
Cron jobs are the unix/linux flavour of job scheduling.
have a look at this link:
Or do a google search for "cron job" for more info.
sarah Marsh
Ranch Hand

Joined: Mar 06, 2001
Posts: 282
Thanks for all the reply.
I take a look of the websites that talk about
the cron job, but there is no one example
telling me how to use "crontab -e" to edit
the crontab file. I tried to use "crontab -e",
but can not get any clue. Please help!
Michael Ernest
High Plains Drifter

Joined: Oct 25, 2000
Posts: 7292

To use crontab's editing facility, you need to set an environment variable called EDITOR, where EDITOR it an editing program like /usr/bin/vi (on Solaris, anyway) or /usr/dt/bin/dtpad (if you're using CDE's notepad tool).
This invocation will bring up the cron table for your account in the editing tool that you set, like so:
$ EDITOR=/usr/bin/vi
$ export EDITOR
$ crontab -e <user>
Of course, none of that tells you the file format that cron uses. For that, read the man page.

Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

This is what a crontab entry that mails a nagging messages to a user's webmail account looks like.
One thing to beware of is that the SYSTEM crontab format is somewhat different that USER crontabs. The example is a user crontab. For safety's sake, it's a good idea to use absolute file references, even though the example doesn't.
Cron is the recommended way to do this stuff because you don't have to do any "real" programming. I DON'T recommend writing a C program that does a poll-and-wait unless you really think that having a CPU usage of 100% means you're getting your money's worth :roll: There is a signal that can be used to allow a C program to sleep until an alloted time.
But a custom C program is really not the "Unix" way. If I were to choose one distinguishing philosphy that's virtually unique to Unix it would be that one never writes a custom app if it's possible to do the same with a string of one or more system tools.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: run a Java application every hour automatically
It's not a secret anymore!