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
Java

Avatar of undefined
Last Comment
for_yan

8/22/2022 - Mon
for_yan

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
for_yan

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
for_yan

this is where you canm download Quartz
http://quartz-scheduler.org/
for_yan

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
for_yan

ASKER
onyourmark

So your recommendation is to use scheduler/chron I think.
for_yan

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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
for_yan

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
ASKER
onyourmark

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
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
for_yan

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
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER
onyourmark

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
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
for_yan

Your third partyu classes (iusually packaged into the jar file) need to be accessible in the cvlasspath
of course also
ASKER
onyourmark

Thanks so much!
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
for_yan

You are always welcome.