2013年9月28日星期六

java time controller

Using java code written in a time controller .
desired effect is that every month on the 10th , the 15th , the 21st automatically run test () method .
please god pointing, I white , preferably with example code. grateful ! ! !
------ Solution ---------------------------------------- ----
that is upgraded , the method can not be used , and you like to try using 1.5.1 jar
------ For reference only ----------- ----------------------------

Timer timer = new Timer();
timer.schedule(new MyTask(), 1000, 2000);

with a timer
an implementation method is executed every point , judgment is not to be performed on the implementation of this day is not executed contrary
Another is set next execution time, execution continues after the expiry of this method is called to set the next
------ For reference only ------------ ---------------------------




The easiest way is that you get the current date , and then put out to compare the interception day , match, call timer .
------ For reference only ------- --------------------------------
I can not meet the requirements of this Yeah ! I run every month on the 10th next month 10 finished running again .
This is the number of seconds after you run MyTask (), then every number of seconds to continue running MyTask ().
can not be determined to run automatically every month on the 10th MyTask ().

------ For reference only ---------------------------------- -----
that I executed in this MyTask (), or after the 10th of each month to continue running MyTask ()
------ For reference only - --------------------------------------

two programs closer look look , the first program , performed daily , if it is the 10th on the implementation of test not just skip
The second program , the 10th execution , after the implementation of the next month on the 10th to set execution , after the implementation of the next month on the 10th next month on the 10th execution settings so that every month on the 10th after execution will set a timer to perform next month on the 10th , do I say I do not know whether you can understand ?
------ For reference only -------------------------------------- -
this on your own for a month on the 10th and the 10th of next month, the number of seconds , and then set down on the line ah
------ For reference only --------- ------------------------------
can use quartz timing tasks , which is particularly suggest you to check all check with CraoTrigger class , Gron expression can control the execution time for example "0 15 10? * 6L" represents the last Friday of every month 10:15 executive
------ For reference only ------------------------------------- -
quartz timing tasks , do not really understand , can you give examples ! !
------ For reference only -------------------------------------- -
need to import a few jar package
commons-logging.jar
log4j-1.2.13.jar
quartz-1.5.1.jar
quartz-all-2.1.7.jar
me this is temporary Minato , non-standard should be unified with the 1.5 version of the
public static void main (String args []) throws ParseException, SchedulerException {

JobDetail jobDetail = new JobDetail ("job1_2", "jGroup1", TaskWorkJob.class);
CronTrigger cronTrigger = new CronTrigger ("trigger1_2", "tgroup1");
cronTrigger.setCronExpression ("0/5 ****?") ;/ / set expressions configured according to individual needs
SchedulerFactory schedulerFactory = new StdSchedulerFactory ();
Scheduler scheduler = schedulerFactory.getScheduler ();
scheduler.scheduleJob (jobDetail, cronTrigger);
scheduler.start ();

}






task categories:
public class TaskWorkJob implements Job {

public void execute (JobExecutionContext arg0) throws JobExecutionException {
/ / TODO Auto-generated method stub
System.out.println (" number of executions " + new Date ());
}

}

------ For reference only ---------------------------------- -----
expressions you use this " 000 10,15,21 * ? " means 15 on the 10th of each month number at 0:00 on the 21st时0 different executive
------ For reference only ------------------------ ---------------
  The reply deleted by an administrator at 2013-09-27 15:47:09

------ For reference only ---------------------------------- -----

"http://www.springframework.org/dtd/spring-beans.dtd">














0 0 0-23 **?
0 0/30 7-23,0 **? ->

0 42 14 **? ->







your way








names are special characters must be allowed values
second is 0-59 , - * /
minutes 0-59 , - * /
time is 0-23 , - * /
Day is 1-31, - *? / L W C
month is 1-12 or JAN-DEC, - * /
Week is 1-7 or SUN-SAT, - *? / L C #
whether empty or years 1970-2099 , - * /

expression Example:

0 * 17 **?

Significance: daily from 17:00 to 5:59 in the afternoon once per minute to stimulate trigger.
it stops at 5:59 pm because the value of the 17 -hour domain at 18 o'clock , the hour into 18 , no longer ignore this trigger, until the next day's 17:00 .
expression Example:

0 10,15 14? 3 WEB

Significance: In March of every Wednesday 2:10 pm and 2:15 pm to be triggered.

"0 0 12 **?" trigger daily 12:00
"0 15 10? **" trigger daily at 10:15 am
"0 15 10 **?" trigger daily at 10:15 am
"0 15 10 **? *" trigger daily at 10:15 am
"0 15 10 **? 2005" 2005 triggered years of daily 10:15 am
"0 * 14 **?" daily 14:00 to 2:59 pm every minute during the trigger
"0 0/5 14 **?" daily 14:00 to 2:55 pm every five minutes during the trigger
"0 0/5 14,18 **?" daily 14:00 to 2:55 during and 18:00 to 6:55 every five minutes during trigger
"0 0-5 14 **?" daily 14:00 to 2:05 pm every minute during the trigger
"0 10,44 14? ​​3 WED" March of each year 2:10 pm Wednesday and 2:44 trigger
"0 15 10? * MON-FRI" Monday through Friday 10:15 am trigger
"0 15 10 15 *?" trigger 15th of the month 10:15 am
"0 15 10 L *?" the last day of each month at 10:15 am trigger
"0 15 10? * 6L" the last Friday of each month at 10:15 am trigger
"0 15 10? * 6L 2002-2005" 2002年to 2005, the last Friday of each month at 10:15 am trigger
"0 15 10? * 6 # 3" the third Friday of each month at 10:15 am trigger

->

public static void main (String [] args) {
new ClassPathXmlApplicationContext ("Spring.xml"). getBean ("callTrigger");
}





------ For reference only ---------------------------------- -----
import java.text.ParseException;
import java.util.Date;

import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;


public class UniversalQuartzManager {
 private static UniversalQuartzManager instance = null;
 private Scheduler sched = null;
 private SchedulerFactory factory = null;

 private UniversalQuartzManager() {
  _init();
 }

 private void _init() {
  factory = new org.quartz.impl.StdSchedulerFactory();
  try {
   sched = factory.getScheduler();
  } catch (SchedulerException e) {
   e.printStackTrace();
  }
 }

 public synchronized static UniversalQuartzManager getInstance() {
  if (instance == null) {
   instance = new UniversalQuartzManager();
  }
  return instance;
 }

 public void start() {
  try {
   sched.start();
   // 在这里加载需要执行的业务逻辑类UniversalQuartz.class
   JobDetail detail = new JobDetail("cmhksynchron", "cmhkSynch",UniversalQuartz.class);
   CronTrigger trigger = new CronTrigger();
   // 手动添加了时间
   trigger.setCronExpression("0/10 * * * * ? *");
//   trigger.setCronExpression("0 0-59 16 * * ?");
   trigger.setName("abintrigger");
   trigger.setStartTime(new Date());
   sched.scheduleJob(detail, trigger);
  } catch (SchedulerException e) {
   e.printStackTrace();
  } catch (ParseException e2) {
   e2.printStackTrace();
  }
 }

 public void stop() {
  try {
   sched.shutdown();
   sched = factory.getScheduler();
  } catch (SchedulerException e) {
   e.printStackTrace();
  }
 }

 public void refresh() {
  // 未知的原因,程序执行这段判断进入stop(),在sched.shutdown();这一句报错,//所以暂时将其屏蔽,以待后来解决
  // try {
  // if(sched != null && sched.isStarted()) {
  // this.stop();
  // }
  this.start();
  // } catch (SchedulerException e) {
  // e.printStackTrace();
  // }
 }

}

I'm 40 and 41 can not initialize the object when initialized
Cannot instantiate the type JobDetail

------ For reference only ---------------------------------- -----
this is the online copied quartz jar package quartz-2.2.1.jar error
I'm 40 and 41 can not initialize the object when initialized
Cannot instantiate the type JobDetail
------ For reference only ------------------------- --------------
ah good thank

没有评论:

发表评论