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 ... 
随机推荐
- 在ubuntu下使用minicom连接交换机/路由器Console口
			首先下载并安装minicom sudo apt-get install minicom 然后将Console线一端连上交换机的Console口,另一端连上电脑(我这里是通过USB口连接的) 然后查看对 ... 
- nyoj_78:圈水池(凸包入门)
			题目链接 将所有点按从左至右顺序排序,然后将所有点先从左到右扫描再从右到左扫描,逐渐将凸包轮廓"勾勒"出来 (凸包轮廓满足,轮廓上连续的三个点按先后顺序给出的话呈逆时针方向) 最后 ... 
- 基于腾讯Centos7云服务器搭建SVN版本控制库
			基于腾讯Centos7云服务器搭建SVN版本控制库 最近在和小伙伴组队参加一个关于人工智能的比赛,无奈不知道怎么处理好每个人的代码托管问题,于是找到了晚上免费svn托管服务器的服务,但是所给的免费空间 ... 
- 2017年1月1日 App Store中的所有应用都必须启用 App Transport Security安全功能
			2017年1月1日 App Store中的所有应用都必须启用 App Transport Security安全功能,否则极有可能被拒! 在WWDC 2016开发者大会上,苹果宣布了一个最后期限:到20 ... 
- Python学习记录----语法学习
			一控制语句 http://blog.csdn.net/lynn_yan/article/details/5464911 if 语句 二 字典详解 http://blog.csdn.net/moodyt ... 
- Jenkins发布MVC应用程序
			一个大的项目一般都会进行模块化.层次化分隔,每个模块.每个层次都可能是一个或多个工程文件组成,而且各个模块都有依赖关系,有先后顺序,先build哪个然后再build哪个都是有顺序的,如果想build一 ... 
- [补档]暑假集训D2总结
			%dalao https://hzoi-mafia.github.io/2017/07/26/17/ (纪念我已死去的github) 大佬AntiLeaf来讲概率&期望,然后--成功变为 不可 ... 
- 微信客户端+微信公众平台+新浪云SAE+Arduino+WS100(控制LED)
			第一步:准备 1.智能手机微信客户端或微信电脑版 2.注册微信公众平台 https://mp.weixin.qq.com 3.注册新浪账号 http://www.sinacloud.com 4.拥有一 ... 
- Hadoop新生报到(一) hadoop2.6.0伪分布式配置详解
			首先先不看理论,搭建起环境之后再看: 搭建伪分布式是为了模拟环境,调试方便. 电脑是win10,用的虚拟机VMware Workstation 12 Pro,跑的Linux系统是centos6.5 , ... 
- 3.commonjs模块
			1.首先建一个math.js exports.add = function(a, b){ return a + b; } exports.sub = function(a, b){ return a ... 
