aspose file tools*
The moose likes Java in General and the fly likes Reding File from a remote server after every 2 minutes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Reding File from a remote server after every 2 minutes" Watch "Reding File from a remote server after every 2 minutes" New topic
Author

Reding File from a remote server after every 2 minutes

Gary Dwivdi
Greenhorn

Joined: Sep 12, 2011
Posts: 9
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
Bartender

Joined: May 31, 2011
Posts: 1776
Hi Garima,

welcome to the Ranch... please check if you can use simple threading concept like below.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36592
    
  16
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

Joined: Mar 10, 2008
Posts: 326

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

Joined: Sep 12, 2011
Posts: 9
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

Joined: Mar 10, 2008
Posts: 326

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

Joined: Sep 12, 2011
Posts: 9
@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

Joined: Oct 13, 2005
Posts: 36592
    
  16
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reding File from a remote server after every 2 minutes
 
Similar Threads
move files from one machine to another
Ant to create properties files?
How to render a web page inside java?
Quartz scheduler or Timer task?
Reading file from remote server using SFTP connection