Java Quartz Scheduler - getScheduledFireTime returning incorrect value -


i have following sample quartz job retrieves web page.

import java.io.bufferedreader; import java.io.inputstreamreader; import java.net.httpurlconnection; import java.net.url;  import org.quartz.job; import org.quartz.jobexecutioncontext; import org.quartz.jobexecutionexception;  public class samplequartzjob implements job {      public void execute(jobexecutioncontext context) throws jobexecutionexception {         system.out.println(context.getjobdetail().getkey().tostring() + " started");         system.out.println("scheduled fire time: " + context.getscheduledfiretime());         system.out.println("fire time: " + context.getfiretime());          try {             sendget();         } catch (exception e) {             e.printstacktrace();         }          system.out.println(context.getjobdetail().getkey().tostring() + " completed");          system.out.println();     }      private void sendget() throws exception {         string url = "https://www.google.com/search?q=abc";          url obj = new url(url);         httpurlconnection con = (httpurlconnection) obj.openconnection();          bufferedreader in = new bufferedreader(new inputstreamreader(con.getinputstream()));         string inputline;         stringbuffer response = new stringbuffer();          while ((inputline = in.readline()) != null) {             response.append(inputline);         }         in.close();     }  } 

following main class creates 5 jobs , schedules them run once every 5 seconds.

import static org.quartz.jobbuilder.newjob;  import javax.xml.bind.jaxbexception;  import org.quartz.cronschedulebuilder; import org.quartz.jobdetail; import org.quartz.scheduler; import org.quartz.schedulerexception; import org.quartz.trigger; import org.quartz.triggerbuilder; import org.quartz.impl.stdschedulerfactory;  public class quartzmainclass {      public void init() throws schedulerexception {         scheduler scheduler = stdschedulerfactory.getdefaultscheduler();         (int = 1; <= 5; i++) {             jobdetail job = newjob(samplequartzjob.class).withidentity("job " + i).build();              trigger trigger = triggerbuilder.newtrigger()                     .withschedule(cronschedulebuilder.cronschedule("0/5 * * * * ?")).build();              scheduler.schedulejob(job, trigger);          }          scheduler.start();      }      public static void main(string[] args) throws jaxbexception, schedulerexception {         quartzmainclass quartzmainclass = new quartzmainclass();         quartzmainclass.init();     } } 

i using thread count of 1

org.quartz.threadpool.threadcount=1

    system.out.println("scheduled fire time: " + context.getscheduledfiretime()); 

should printing scheduled times similar following:

12:00:00 // job 1 12:00:00 // job 2 .. 12:00:00 // job 5  12:00:05 // job 1 12:00:05 // job 2 .. 12:00:05 // job 5 

i getting expected output @ times. sometimes, scheduledfiretime getting printed incorrect. off correct time few seconds. wrong code using?

  1. look @ javadoc of

    getscheduledfiretime

  2. your job pretty heavyweight , yet have 5 of them scheduled start every 5 seconds each, having 1 thread quartz. can choke quartz


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -