File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Linux / UNIX and the fly likes run a Java application every hour automatically Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Reply Bookmark "run a Java application every hour automatically" Watch "run a Java application every hour automatically" New topic
Author

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,
Sarah
Gregg Bolinger
Sheriff

Joined: Jul 11, 2001
Posts: 15040

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.


My Blog | DZone Articles
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:
http://www.learninglinux.com/article.php?sid=57
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
Sheriff

Joined: Oct 25, 2000
Posts: 7231

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: 12510


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.


One of the most odious afflictions that Business has inflicted on the modern English language is "pro-active". Most of the time it's simply redundantly used in place of the simple old word "active". And a good deal of the rest of the time it means "You're not overworked enough yet, so go out and find more!"
 
 
subject: run a Java application every hour automatically
 
Threads others viewed
Programatically Running a script file in DOS via Java Application
How to run java application automatically
Running jars from a java application
invoke shell script, by clicking on swing application button
how to run Java program at specific time(without manual intervention)
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com