Link to home
Start Free TrialLog in
Avatar of onyourmark
onyourmark

asked on

setting a timer in Java

I have Java code which I would like to run at certain times during the day. I have Windows 2008 Server but I might also be able to do this on a Linux server.
Most of the code is in a file I have attached. I want to add code to read from a database and write to a database (both databases will be remote and won't be on this server).

I am wondering what the best way to have this code run at a certain times. Should I user window's scheduler or chron or is there some way within the java code to have it run at certain times? Also, I can compile this code into a class file. Will the be sufficient to run it or do I have to put it in a jar file? Note, in order for the file to run it needs other classes . These classes are from an open source Java program called Weka. I was going to install it on the server as well. Will this work?

Thanks for you help in advance!
JavaWekaJ48TestTrainPred2.java
Avatar of for_yan
for_yan
Flag of United States of America image

If you want to have it in pure java you can either use Timer and TimeTask classes
or ExctutoThreadPool. You can also download and use java Quartz library
SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
this is where you canm download Quartz
http://quartz-scheduler.org/
Avatar of onyourmark
onyourmark

ASKER

So your recommendation is to use scheduler/chron I think.
The issues related to reading/writing database or using third ;party java classes are hardly relevant - you can scheduel your runs for any java program or java process any of these ways
Yes, if this is somethiong noot happening on every minute scale, I'd think that cron or windows scheduler will provide less overhead and will take care of your schedule not worse than from within java
Thanks. OK, also what about compiling this code into a class file. Will that be sufficient to run it or do I have to put it in a jar file? Note, in order for the file to run it needs other classes . These classes are from an open source Java program called Weka. I was going to install it on the server as well. Will this work?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In general this is not important if you run your java program from a collection of classes or you pakage them into a jkar file bfore, the main thing that they should be present in the classpath and classpath should be correct; wheteher they are jarred or not is not relevant
So I don't need to do more than make them into class files? Is it hard to get them to run using the scheduler?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Your third partyu classes (iusually packaged into the jar file) need to be accessible in the cvlasspath
of course also
Thanks so much!
You are always welcome.