java project spring job 定时
如题 : 这样的如何配置 。希望给源码 。谢谢!!
在线等!!!急!!!
分享到:
------解决方案--------------------
临时写的。
采用的 quartz-all-1.6.5.jar
import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public class SimpleJob implements Job {
private static final Logger LOGGER = Logger.getLogger(SimpleJob.class);
@Override
public void execute(JobExecutionContext arg0)
throws JobExecutionException {
LOGGER.info("start to work.");
}
}
import java.text.ParseException;
import java.util.Date;
import org.apache.log4j.Logger;
import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.impl.StdSchedulerFactory;
public class QuartzTest {
private static final Logger LOGGER = Logger.getLogger(QuartzTest.class);
public void runScheduler(String cronExpression) {
Scheduler scheduler = null;
try {
// Create a default instance of the Scheduler
scheduler = StdSchedulerFactory.getDefaultScheduler();
scheduler.start();
LOGGER.info("Scheduler was started at " + new Date());
// Create the JobDetail
JobDetail jobDetail = new JobDetail("PrintInfoJob",
Scheduler.DEFAULT_GROUP, SimpleJob.class);
// Create a CronTrigger
try {
CronTrigger trigger = new CronTrigger("CronTrigger", null,
cronExpression);
scheduler.scheduleJob(jobDetail, trigger);
} catch (ParseException ex) {
LOGGER.error("Error parsing cron expr", ex);
}
} catch (SchedulerException ex) {
LOGGER.error(ex);
}
}
/**
* @param args
*/
public static void main(String[] args) {
String cronExpression = "0/5 * * * * ? *";
QuartzTest test = new QuartzTest();
test.runScheduler(cronExpression);
}
}
------解决方案--------------------
package com.vista.quartz;
import java.io.File;
import java.io.FileFilter;
public class FileExtensionFileFilter implements FileFilter
{
private String extension;//文件后缀
public FileExtensionFileFilter(String extension)
{
this.extension = extension;
}
public boolean accept(File file)
{//只接受指定后缀的文件
// Lowercase the filename for easier comparison
String lCaseFilename = file.getName().toLowerCase();//小写化
return (file.isFile() &&(lCaseFilename.indexOf(extension) > 0 )) ? true : false ;
}
}
package com.vista.quartz;
import java.util.Date;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import org.quartz.TriggerUtils;
import org.quartz.impl.StdSchedulerFactory;
public class SimpleScheduler
{