Jfinal 定时 任务

JFinal 定时任务

1、maven中添加quartz插件的jar包,下载见附件

```
		
		
		    cn.dreampie
		    jfinal-quartz
		    0.2
		
```
2、定时任务QuartzJob.java

```
public class QuartzJob implements Job{

	@Override
	public void execute(JobExecutionContext arg0) throws JobExecutionException {
		System.out.println("***************************");
		
	}

}

```

3、配置文件jobs.properties

```
job.channel.class=com.xxx.quartz.QuartzJob
job.channel.group=default
job.channel.id=1
job.channel.cron=*/5 * * * * ?
job.channel.enable=true
```
4、confirg中加载定时器的配置文件

```
	public void configPlugin(Plugins plugins) {
		logger.info("配置插件");
	//定时任务一
        QuartzPlugin quartz = new QuartzPlugin();
        quartz.setJobs("jobs.properties");
        plugins.add(quartz);
        //定时任务二
//        QuartzPlugin quartz2 = new QuartzPlugin();
//        quartz2.setJobs("jobs2.properties");
//        plugins.add(quartz2);
		
		DruidPlugin dp = new DruidPlugin(getProperty("jdbcUrl"),
				getProperty("user"), getProperty("password"));
		dp.addFilter(new StatFilter());
		WallFilter wall = new WallFilter();
		wall.setDbType("mysql");
		dp.addFilter(wall);
		plugins.add(dp);
		ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
		arp.setShowSql(true);
		plugins.add(arp);
		arp.addMapping("goods", Goods.class);
		logger.info("activeRecord表映射成功");
	}
```

你可能感兴趣的:(jfinal)