0

I am attempting to write a java program that will use jsoup to parse a page to look for a certain tag value. If that tag value changes, it will trigger an email update to a preconfigured address. I want to know if there is a way to make this run in the background at all times. I dont know much about linux but i have heard of cron jobs that can do this task. Is there a way to use java to accomplish this? Essentially i would like to be updated within the hour of a change in a webpage field that my java program is determining. If anyone can pitch in on exactly how to accomplish my goal, i would really appreciate it!

4

1 回答 1

1

Without any third party or Licensed tools or API , you can achieve using java built-in

TimerTask and Timer LINK

java.util.*;

public class TimerDemo {
   public static void main(String[] args) {
      // creating timer task, timer
      TimerTask tasknew = new TimerScheduleFixedRate();
      Timer timer = new Timer();

      // scheduling the task at fixed rate
      timer.scheduleAtFixedRate(tasknew,new Date(),1000);      
   }
   // this method performs the task
   public void run() {
      System.out.println("working at fixed rate");      
   }    
}.

    import java.util.*;

    public class TimerDemo {
       public static void main(String[] args) {
          // creating timer task, timer
          TimerTask tasknew = new TimerScheduleFixedRate();
          Timer timer = new Timer();

          // scheduling the task at fixed rate
          timer.scheduleAtFixedRate(tasknew,new Date(),1000);      
       }
       // this method performs the task
       public void run() {
          System.out.println("working at fixed rate");      
       }    
    }
于 2013-06-11T03:24:05.830 回答