I need to run a java program on the cron but due to my server limitations I am not able to do so. So I have decided to run the program mannually once a week but I have following problems: 1. How do start the program on the UNIX system run time? 2. How can I know if the last instance of th program is still running on run time? Thanks.
1. I'd write a shell script, much like a windows batch file. You could simply execute the script, or since you're doing it manually, just ensure that your java class file is in your path, and type 'java MyJavaProgram' at the prompt.
2. ps -ef |grep 'java' This generates a full list of active processes, and then strips out any line that doesn't have 'java' in it.
There might be numerous java processes running on the box, so you'd have to be careful with that one.
There are other ways of doing this sort of thing. For example, open a file at the start of the program write 'RUNNING' to it, and close it. At the end of your program, open the same file, overwrite the 'RUNNING' with 'STOPPED' and close the file again. So if you want to know if your program is running, type 'more MyFileName'
Joined: Jan 13, 2002
Hi, How about using the java.util.Timer class to schedule the jobs. I've not used it but I've heard good reports. Thanks, Steve
Joined: Jan 22, 2002
The timer class works well for us as well. As to start with unix why not invoke your script from rc? Also some application server products have their own timer implementations exposed that can be useful. Watch out here though. They are proprietary. What out also with programs with shutdown hooks in the background. You will have to nohup these to prevent the hook from firing prematurely. You can get a behavior similar to rc with a product like: http://www.eworksmart.com/JNT/