jeecgboot定时任务示例(解决springboot和jeecgboot框架定时任务突然无效问题)【伸手党福利】

主要解决springboot定时任务不起作用或无效(不工作)的问题。
本次案例当中,由于之前在运行环境中正常运行,最近突然不工作,重启服务无效,所以进行了大量排查,最终结论形成以下示例:

springboot自带的后端示例

伸手党版本:

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api(tags="1示例")
@RestController
@EnableScheduling
@RequestMapping("/index")
public class index {
    //    @Autowired

    @AutoLog(value="示例")
    @ApiOperation("二级菜单内容")
//    extends JeecgController<Object,>
    @GetMapping(value = "/demo")
    public Result<?> test() {
        return  Result.ok("111111");
    }

    //定时任务
    @Scheduled(cron="0 * * * * ?")
    public void phjob() {
        System.out.println("标准定时任务(每分钟)");
    }
}

核心版本(0 * * * * ?这一段表示每分钟)

@EnableScheduling
public class index {
@Scheduled(cron="0 * * * * ?")
    public void phjob() {
        System.out.println("标准定时任务(每分钟)");
    }
}

jeecgboot版本:(框架版本,用于分布式部署,防止重复执行)【伸手党福利】

package org.jeecg.module.index.Job;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.stereotype.Component;
//
//定时任务模块
//使用方式:在此处使用示例进行设置,然后在后台系统监控》定时任务当中,将此包中的方法名写入运行,运行之后能够随时调节运行周期。
//此方法的主要初衷在于解决分布式部署时候,定时任务重复启动的问题。
//By:faser


@Slf4j
@Component
public class schedued implements Job{
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        System.out.println("定时任务(每分钟)");
    }
}

这个包需要到后台的系统监控》定时任务当中设置运行间隔,本案例中需要输入的运行函数名:
org.jeecg.module.index.Job.schedued即包名+类名,execute为固定格式

设置结果:
在这里插入图片描述

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值