Springboot+resteasy定时任务
- 定时任务
需求:按每日统计点赞数、评论数、热度的增加量(不是现有量)
1.每天零点执行:首先遍历出user的统计字段
然后插入到新创建的表中。
2.每天一点执行:根据时间段将两表的数据相减
创建增量字段,更新记录下来
package com.xgt.task; import com.xgt.bean.StatisticsUserBean;
import com.xgt.bean.UserBean;
import com.xgt.dao.entity.StatisticsUser;
import com.xgt.dao.entity.User;
import com.xgt.service.StatisticsService;
import com.xgt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import java.util.List; /**
* Created by Administrator on 2017/8/14.
*/
@Component//当组件不好归类的时候,我们可以使用这个注解进行标注。
@Configurable//自动注入bean
@EnableScheduling//开启计划任务的支持。
public class StatisticsUserStorage {
@Autowired
private UserService userService;
@Autowired
private StatisticsService statisticsService;
@Scheduled(cron = "0 0 0 * * ?")//每天零点执行
private void initialStatistics(){
List<User> statisticsList = statisticsService.selectUserAsStatistics();
for (User statistics:statisticsList){
UserBean user = new UserBean();
user.setUserId(String.valueOf(statistics.getUserId()));
user.setHeat(statistics.getHeat());
user.setLikeCount(statistics.getLikeCount());
user.setShareTimes(statistics.getShareTimes());
statisticsService.insertStatistics(user);
} }
@Scheduled(cron = "0 0 1 * * ?")//每天凌晨一点执行
private void generateStatistics(){
List<StatisticsUser> statisticsUserList = statisticsService.subtractTwoTables();
for (StatisticsUser statisticsUser:statisticsUserList){
StatisticsUserBean statisticsUserBean = new StatisticsUserBean();
statisticsUserBean.setLikeCountIncrement(statisticsUser.getLikeCountIncrement());
statisticsUserBean.setHeatIncrement(statisticsUser.getHeatIncrement());
statisticsUserBean.setShareTimesIncrement(statisticsUser.getShareTimesIncrement());
statisticsService.updateStatistics(statisticsUserBean);
}
}
}
Springboot+resteasy定时任务的更多相关文章
- 玩转SpringBoot之定时任务详解
序言 使用SpringBoot创建定时任务非常简单,目前主要有以下三种创建方式: 一.基于注解(@Scheduled) 二.基于接口(SchedulingConfigurer) 前者相信大家都很熟悉, ...
- SpringBoot 配置定时任务
SpringBoot启用定时任务,其内部集成了成熟的框架,因此我们可以很简单的使用它. 开启定时任务 @SpringBootApplication //设置扫描的组件的包 @ComponentScan ...
- SpringBoot - 添加定时任务
SpringBoot 添加定时任务 EXample1: import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spri ...
- springboot之定时任务
定时线程 说到定时任务,通常会想到JDK自带的定时线程来执行,定时任务. 回顾一下定时线程池. public static ScheduledExecutorService newScheduledT ...
- SpringBoot整合定时任务和异步任务处理 3节课
1.SpringBoot定时任务schedule讲解 定时任务应用场景: 简介:讲解什么是定时任务和常见定时任务区别 1.常见定时任务 Java自带的java.util.Timer类 ...
- 十三、springboot集成定时任务(Scheduling Tasks)
定时任务(Scheduling Tasks) 在springboot创建定时任务比较简单,只需2步: 1.在程序的入口加上@EnableScheduling注解. 2.在定时方法上加@Schedule ...
- SpringBoot创建定时任务
之前总结过spring+quartz实现定时任务的整合http://www.cnblogs.com/gdpuzxs/p/6663725.html,而springboot创建定时任务则是相当简单. (1 ...
- springboot开启定时任务 添加定时任务 推送
最近在自学Java的springboot框架,要用到定时推送消息.参考了网上的教程,自己调试,终于调好了.下面将网上的教程归纳下,总结复习下. springboot开启定时任务 在SpringBo ...
- (入门SpringBoot)SpringBoot结合定时任务task(十)
SpringBoot整合定时任务task 使用注解EnableScheduling在启动类上. 定义@Component作为组件被容器扫描. 表达式生成地址:http://cron.qqe2.com ...
随机推荐
- Vulkan Tutorial 29 Loading models
操作系统:Windows8.1 显卡:Nivida GTX965M 开发工具:Visual Studio 2017 Introduction 应用程序现在已经可以渲染纹理3D模型,但是 vertice ...
- Struts2从头到脚--学习笔记(自认为比较重要的)
一. Struts2框架介绍 Struts2是一个基于MVC设计模式的Web应用框架,它本质上相当于一个servlet,在MVC设计模式中,Struts2作为控制器(Controller)来建立模型与 ...
- nyoj_1022:合纵连横(并查集删点)
题目链接 参考链接 只附代码好了 #include<bits/stdc++.h> using namespace std; ; int a[N],b[N],vis[N]; int n,m, ...
- 部署DNS服务
DNS,全称Domain Name System,即域名解析系统. DNS帮助用户在互联网上寻找路径.在互联网上的每一个计算机都拥有一个唯一的地址,称作"IP地址"(即互联网协议地 ...
- 初次配置git与github出现push不了的问题
ssh: connect to host gmail.com port 22: No route to host fatal: Could not read from remote repositor ...
- PHP中通过sqlsrv调用存储过程——成绩排名去除重复字段的数据行
培训考试项目中,需要实现考试成绩排名:排名参考项为分数(score降序).参加日期(attendtime升序).第几次参加考试(frequency升序):并且,每个用户只保留一条数据(pid). 考试 ...
- ThreadLocal源码分析(转)
阅读总结: ThreadLocal内部使用静态map存储,每个变量对应一个hashcode,不需要指定key值,后台动态生成,good! 每个变量ThreadLocal内部分配Entry,获取值时,通 ...
- [BZOJ 1500]维修数列 [Splay Tree从进阶到住院]
历尽艰辛终于A掉了这题QwQ 贴COGS评论区几句话=.= 策爷:"splay/块状链表的自虐题.".深刻理解到如果没有M倾向就不要去写这题了.. -Chenyao2333 记得b ...
- dubbo源码分析(二):超时原理以及应用场景
dubbo超时原理以及应用场景 *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: ...
- python教程6-3:排序
(a).输入一串数字.并从大到小排列. (b).跟a一样,不过要用字典序从大到小排列. python35 PaiXu_6_3.py PaiXu_6_3.py #coding=utf-8 import ...