aspose file tools*
The moose likes Servlets and the fly likes Java Run Time & Cron Prog Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Java Run Time & Cron Prog" Watch "Java Run Time & Cron Prog" New topic
Author

Java Run Time & Cron Prog

Vikas Aggarwal
Ranch Hand

Joined: Jun 22, 2001
Posts: 140
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.


Vikas Aggarwal

Founder @
Leads and Deals Limited

www.LeadsAndDeals.com
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

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'
Steve Granton
Ranch Hand

Joined: Jan 13, 2002
Posts: 200
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
Don Schaefer
Greenhorn

Joined: Jan 22, 2002
Posts: 16
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/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Run Time & Cron Prog