技术标签: 其它
1、首先在porm.xml文件引入如下依赖:
2、新建一个任务类(如下面代码中的CommentLikeJob),这个类要继承QuartzJobBean父类,实现void executeInternal()方法,方法内为定时任务的业务逻辑(下面代码的业务逻辑可以不用理会),此外,可以在任务类里面通过@Autowired或者@Resource注入被Spring托管的Bean来使用。
import com.tkt.commons.utils.RedisUtil;
import com.tkt.dao.TktCommentLikeMapper;
import com.tkt.dao.TktCommentMapper;
import com.tkt.domain.TktCommentLike;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
/**
* @description: 更新评论点赞数据任务
* @author: xiexuan
* @time: 2019/12/20 22:02
*/
public class ComentLikedJob extends QuartzJobBean {
@Resource
private TktCommentLikeMapper tktCommentLikeMapper;
@Resource
private TktCommentMapper tktCommentMapper;
@Autowired
private StringRedisTemplate stringRedisTemplate;
@Override
protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
System.out.println("定时任务开启======================");
this.updateCommentLikeData();
System.out.println("定时任务结束======================");
}
private void updateCommentLikeData(){
Set<String> keys = RedisUtil.scan(stringRedisTemplate, "*like*");
List<String> values = stringRedisTemplate.opsForValue().multiGet(keys);
Iterator<String> keyIterator = keys.iterator();
Iterator<String> valueIterator = values.iterator();
while (keyIterator.hasNext()){
String[] keyArray = keyIterator.next().split("::");
Long commentId = Long.parseLong(keyArray[1]);
Long userId = Long.parseLong(keyArray[2]);
String[] valueArray = valueIterator.next().split("::");
Date likedTime = new Date(Long.parseLong(valueArray[0]));
int likedStatue = Integer.parseInt(valueArray[1]);
Example example = new Example(TktCommentLike.class);
example.createCriteria().andEqualTo("likedUserId", userId).andEqualTo("likedCommentId", commentId);
TktCommentLike tktCommentLike = tktCommentLikeMapper.selectOneByExample(example);
if (tktCommentLike != null){
tktCommentLike.setLikedStatus(likedStatue);
tktCommentLike.setUpdateTime(likedTime);
tktCommentLikeMapper.updateByPrimaryKeySelective(tktCommentLike);
}else {
tktCommentLike = new TktCommentLike(userId, commentId, likedStatue, likedTime, likedTime);
tktCommentLikeMapper.insert(tktCommentLike);
}
}
}
3、新建一个配置类QuartzConfig,配置类里面返回一个JobDetail类和Trigger触发器类,Trigger类里面为定时任务的调度策略
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @description: quartz配置类
* @author: xiexuan
* @time: 2019/12/23 21:35
*/
@Configuration
public class QuartzConfig {
@Bean
public JobDetail quartzDetail(){
return JobBuilder.newJob(ComentLikedJob.class).withIdentity("commentLikeTaskQuartz").storeDurably().build();
}
@Bean
public Trigger quartzTrigger(){
SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
.withIntervalInMinutes(5)
.repeatForever();
return TriggerBuilder.newTrigger().forJob(quartzDetail())
.withIdentity("commentLikeTaskQuartz")
.withSchedule(scheduleBuilder)
.build();
}
}
4、最后要在SpringBoot的Application启动类上面加上@EnableScheduling注解开启定时任务,就可以简单实现Quartz定时任务了。
在使用可视化树的过程中,报错了。说是‘dot.exe’not found in path原代码:# import tools needed for visualizationfrom sklearn.tree import export_graphvizimport pydot#Pull out one tree from the foresttree = rf.estimat...
post请求一般限制大小为2M,传递的数据如果超过2M后台就会无法接收数据如果传输数据超过2M,需要在配置文件中设置springboot项目在配置文件中设置如下:server.tomcat.max-http-post-size: -1如果是用的Tomcat,则需要在server.xml里面设置如下,设置maxPostSize="-1" 如果Tomcat版本在7之前,设置maxP...
大家都知道,日志是同步输出出来的。输出日志非常影响主线程执行效率。多线程打印日志会出线日志混乱的情况,一页日志可能包含了N个请求信息,影响问题排查效率。在没有适合的搜索工具...
使用python----pygame模块开发外星人入侵(本项目来自于python编程—从入门到实践第二版第一个项目)pygame相关详情链接这是书上的项目,严格来说,这不算自己开发的项目,但是将本项目重写一段也能收获到很多,比如:如何管理包含多个文件的项目,重构许多代码并且管理文件内容,复制一次经典的项目开发流程,阅读本书上项目开发作者的开发思路以及经验等等:本次项目包含7个py文件以及一个images文件夹setting.pyclass Settings(): """存储《外星人入侵
开发基于 OpenGL 的应用程序,必须先了解 OpenGL 的库函数。它采用 C 语言风 格,提供大量的函数来进行图形的处理和显示。OpenGL 库函数的命名方式非常 有规律。所有 OpenGL 函数采用了以下格式: 库前缀有 gl、glu、aux、glut、wgl、glx、agl 等等,分别表示该函数属于 OpenGL 那个开发库,从函数名后面中还可以看出需要多少个参数以及参数的 类型
JVM垃圾回收优化实战-G1垃圾回收器
一、下载openssl http://sourceforge.net/projects/gnuwin32/files/openssl/0.9.8h-1/openssl-0.9.8h-1-bin.zip/download?use_mirror=nchc二、然后解压把openssl.exe放在C:\Program Files\Java\jdk1.8.0_45\bin文件夹下
Description圆方树板子,自己看。。。Sample Input5 7 21 21 31 42 32 43 41 51 42 5Sample Output12写这篇博客完全是为了存个板子,谢谢。#include &amp;lt;vector&amp;gt;#include &amp;lt;cstdio&amp;gt;#include &amp;lt;cstring&
李嘉诚又有新动作了!7月23日晚,李嘉诚家族名下的长实集团发布公告称,以总价约71.02亿元(约10.12亿美元)价格,把旗下成都“南城都汇”项目,卖给“禹洲集团”和“成都瑞卓置业有限公司”,两家房企一人一半(各占50%股权);而李嘉诚将从中“赚”(未经审核收益)约38.11亿元。李嘉诚71亿卖掉成都“地王”7月23日晚,李嘉诚旗下公司长实集团发布了一则公告。公告称,由长实集团子公司所持有的成都南城都汇项目卖了,接盘方为一家名为RZ3262019 Limited的公司,股东分别为禹州集团控股有限公司
openssl-1.0.1p源码安装后,依赖于openssl.so库的应用报错libcrypto.so.1.0.0: no version information available解法:1. 创建 /tmp/openssl.ld,如下:OPENSSL_1.0.0 { global: *;};OPENSSL_1.0.1 { new*;}OPENSSL_1.0.0;OPENSSL_1.0.1p...
原文地址:https://www.cnblogs.com/weifeng1463/p/6825532.htmlSysctl命令及linux内核参数调整一、Sysctl命令用来配置与显示在/proc/sys目录中的内核参数.如果想使参数长期保存,可以通过编辑/etc/sysctl.conf文件来实现。命令格式:sysctl [-n] [-e] -w variab...
今天本来想简单对Rewrite解释一下,发现这个功能太庞大了,自己也是参考多方资料,加上自己的部分理解,汇总了一下,如有问题,我们群里沟通。1、Rewrite简介 Rewirte主要的功能就是实现URL的跳转,隐藏URL真实地址,可以帮组我们实现拟静态,拟目录,域名跳转,防止盗链,搜索引擎得收录等。Rewirte配置可以通过服务器级的(httpd.conf)和目录级的 (