This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Run Time & Cron Prog

 
Vikas Aggarwal
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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/
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic