关注JEECG发展历程 关注最新动态和版本, 记录JEECG成长点滴 更新日志 - 技术支持 - 招聘英才

JEECG最新版本下载 JEECG智能开发平台 - 显著提高开发效率 常见问题 - 入门视频 - 参与开源团队

商务QQ: 69893005、3102411850 商务热线(5*8小时): 010-64808099 官方邮箱: jeecgos@163.com

查看: 15021|回复: 9

jeecg 3.7.1 新版功能,集群定时任务动态发布模块 使用规则

[复制链接]
发表于 2017-8-24 10:12:08 | 显示全部楼层 |阅读模式
jeecg 3.7.1  集群定时任务动态发布模块 使用规则

新版特性:    支持集群定时任务,支持分布式。
菜单路径: 系统监控--》定时任务
字段说明:
任务ID、任务说明:自定义即可
cron表达式:
          定义任务触发的时间规则。提供一个在线生成cron的地址,http://cron.qqe2.com/
任务类名:
          执行定时任务的业务类,实现org.quartz.Job接口,任务触发时系统自动执行execute方法。格式:包名.类名,举例:com.mypackage.ClassName
执行服务器IP
         集群专用,配置执行该任务的服务器IP地址。单台服务器非集群环境,默认“本地”即可。
远程主机:集群专用,配置接受指令的服务器地址(格式:IP、域名 [端口] + 项目名,举例:192.168.100/jeecg)。
       当“执行服务器IP”与当前服务器IP不匹配时,系统会将启动定时任务的指令发送到该主机,以通知“远程主机”启动该定时任务。单台服务器非集群环境,默认“本地”即可。

源码下载地址:http://git.oschina.net/jeecg/jeecg
发表于 2017-9-12 16:43:05 | 显示全部楼层
http://git.oschina.net/jeecg/jeecg 这里有3.7.1版本???
你2017-8-24发布的3.7.1但是oschina最后的修改时间是2个月前。
发表于 2017-9-13 17:11:15 | 显示全部楼层
版主给打个整体的包吧, maven弄不下来
发表于 2017-9-14 14:59:34 | 显示全部楼层
怎样才能与之前3.7的版本进行整合呢?主要改哪些东西。
发表于 2017-10-23 09:34:27 | 显示全部楼层
3.7.1  版本  提供的 定时任务例子 service 注入为 null   代码中报错信息直接不打印 .
请问 系统如何合理注入容器对象.?
org.jeecgframework.web.system.sms.util.task.SmsSendTask
-->
public class SmsSendTask implements Job{
   
    @Autowired
    private TSSmsServiceI tSSmsService;  注入为null
   
    /*@Scheduled(cron="0 0/1 * * * ?")*/
    public void run() {
        long start = System.currentTimeMillis();
        org.jeecgframework.core.util.LogUtil.info("===================推送消息定时任务开始===================");
        try {
            tSSmsService.send();
        } catch (Exception e) {
            //e.printStackTrace();
        }
        org.jeecgframework.core.util.LogUtil.info("===================推送消息定时任务结束===================");
        long end = System.currentTimeMillis();
        long times = end - start;
        org.jeecgframework.core.util.LogUtil.info("总耗时"+times+"毫秒");
    }

代码位置

代码位置
发表于 2017-10-23 09:44:46 | 显示全部楼层
3.7.1 版本
定时任务 立即生效 有问题.
检查发现 点击立即生效之后 就是仅仅执行更新定时任务对象的操作而已.  而已由于页面没有传 cron 表达式参数导致保存数据报错. .
具体实现:
org.jeecgframework.core.timer.DynamicTask.updateCronExpression(TSTimeTaskEntity)
public boolean updateCronExpression(TSTimeTaskEntity task) {        
        
        try {
            String newExpression = task.getCronExpression();     // 此处获取的   newExpression 为NULL
            task = timeTaskService.get(TSTimeTaskEntity.class, task.getId());        
            
            //任务运行中
            if("1".equals(task.getIsStart())){
                CronTriggerBean trigger = (CronTriggerBean)schedulerFactory.getTrigger("cron_" + task.getId(), Scheduler.DEFAULT_GROUP);            
                String originExpression = trigger.getCronExpression();      
                //检查运行中的任务触发规则是否与新规则一致
                if (!originExpression.equalsIgnoreCase(newExpression)) {  
                    trigger.setCronExpression(newExpression);  
                    schedulerFactory.rescheduleJob("cron_" + task.getId(), Scheduler.DEFAULT_GROUP, trigger);
                }
            }
            
            //检查数据库中的任务触发规则与新规则是否一致
            if (!task.getCronExpression().equalsIgnoreCase(newExpression)) {  
                task.setCronExpression(newExpression);
                timeTaskService.updateEntitie(task);  // 执行 update 报错 . CronExpression 不能为NULL
            }
            
            return true;




duix2 .jpg
发表于 2017-11-5 01:02:47 | 显示全部楼层
sam_wang 发表于 2017-10-23 09:34
3.7.1  版本  提供的 定时任务例子 service 注入为 null   代码中报错信息直接不打印 .
请问 系统如何合理 ...

测试遇到了相同的问题的路过。。。
发表于 2017-11-10 17:08:44 | 显示全部楼层
本帖最后由 epi999 于 2017-11-10 17:30 编辑
epi999 发表于 2017-11-5 01:02
测试遇到了相同的问题的路过。。。

自己解决了,quartz也换成2.2.3l了
新建一个 类集成 SpringBeanJobFactory 然后在spring-mvc中加载
        <!-- JobFactory -->
        <bean id="xJobFactory" class="org.jeecgframework.core.timer.XJobFactory"></bean>
然后重写定时任务调度器
                <!-- 定时任务调度器 -->
        <bean id="schedulerFactory" lazy-init="false" autowire="no"
                class="org.jeecgframework.core.timer.DataBaseSchedulerFactoryBean">
               
        <property name="jobFactory" ref="xJobFactory"></property>

        </bean>
1.png
2.png
3.png
E:\1.png
E:\2.png
E:\3.png
对照图2,3,你就会发现@autowire注入成功并获取了数据库的信息

1.6换成2.2.3要改的几个地方
11.png
12.png
13.png




发表于 2017-12-25 17:54:06 | 显示全部楼层
SmsSendTask示例中增加一行代码后,解决了null问题。
        @Override
        public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
                SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
                run();
        }
发表于 2018-1-9 10:34:35 | 显示全部楼层
虚对虚
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表