• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Reding File from a remote server after every 2 minutes

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Garima,

welcome to the Ranch... please check if you can use simple threading concept like below.
 
Marshal
Posts: 71722
312
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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®.
 
Ranch Hand
Posts: 326
Android Mac OS X Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Mac OS X Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 71722
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
 
You're not going crazy. You're going sane in a crazy word. Find comfort in this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic