• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reding File from a remote server after every 2 minutes

 
Gary Dwivdi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
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???
TIA
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Garima,

welcome to the Ranch... please check if you can use simple threading concept like below.
 
Campbell Ritchie
Sheriff
Posts: 51332
86
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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®.
 
Ove Lindström
Ranch Hand
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or why not try out the java.util.concurrent.ScheduledExecutorService...


http://download.oracle.com/javase/7/docs/api/java/util/concurrent/ScheduledExecutorService.html
 
Gary Dwivdi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ove Lindström
Ranch Hand
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gary Dwivdi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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)..
 
Campbell Ritchie
Sheriff
Posts: 51332
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic