This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have a requirement where in i have to read a log file from a remote server every two minutes to check the status of the logs.
i have wriiten the code to read the file but m stuck on scheduling it.This code will further be used in Ant script.
Please help me with this.
Is there a way this scheduling can be done using ANT or in java itself???
That might be inefficient, keeping the JVM idle for two minutes at a time (120000 rather than 2000 milliseconds), but I am not sure. You can try a Timer (probably the java.util sort). There are scheduling applications, eg cron on *nix, and there is something similar on Windows®.
Garima Dubey wrote:Thanks a ton guys for the pointers . ..But since i'm calling this class thru an ANT script. can i have something in ANT -any task in ANT which can be used for this.
IMHO, that is not the way Ant should be used. Ant is, sort of, a scripting language that should be used to run a task from point A to point B. Having an Ant-script that calls a Java program every 2 minutes is to use the wrong tool for the wrong job. Ok to start your program with Ant, but not trigger it every 2 minutes. Then I would use a cron job or actually have the program just running and execute a worker every 120 seconds.
But there are tasks to do what you want. And since Ant is extended using Java... all they do is setting up a scheduler of some sort (like the one from the Executor framework) and then call the class that needs to be executed. Sometimes, that is the only thing you can do, if you do not have any other control of the code.
Joined: Sep 12, 2011
@thanks a ton for your suggestions....
I scheduled it by setting up a flag which tests for a codn and if the condn is true ...the log file is read again after a time interval of 2 min ...by using Wait(n sec)..