• 定时任务

  需求:按每日统计点赞数、评论数、热度的增加量(不是现有量)

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定时任务的更多相关文章

  1. 玩转SpringBoot之定时任务详解

    序言 使用SpringBoot创建定时任务非常简单,目前主要有以下三种创建方式: 一.基于注解(@Scheduled) 二.基于接口(SchedulingConfigurer) 前者相信大家都很熟悉, ...

  2. SpringBoot 配置定时任务

    SpringBoot启用定时任务,其内部集成了成熟的框架,因此我们可以很简单的使用它. 开启定时任务 @SpringBootApplication //设置扫描的组件的包 @ComponentScan ...

  3. SpringBoot - 添加定时任务

    SpringBoot 添加定时任务 EXample1: import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spri ...

  4. springboot之定时任务

    定时线程 说到定时任务,通常会想到JDK自带的定时线程来执行,定时任务. 回顾一下定时线程池. public static ScheduledExecutorService newScheduledT ...

  5. SpringBoot整合定时任务和异步任务处理 3节课

    1.SpringBoot定时任务schedule讲解   定时任务应用场景: 简介:讲解什么是定时任务和常见定时任务区别 1.常见定时任务 Java自带的java.util.Timer类        ...

  6. 十三、springboot集成定时任务(Scheduling Tasks)

    定时任务(Scheduling Tasks) 在springboot创建定时任务比较简单,只需2步: 1.在程序的入口加上@EnableScheduling注解. 2.在定时方法上加@Schedule ...

  7. SpringBoot创建定时任务

    之前总结过spring+quartz实现定时任务的整合http://www.cnblogs.com/gdpuzxs/p/6663725.html,而springboot创建定时任务则是相当简单. (1 ...

  8. springboot开启定时任务 添加定时任务 推送

    最近在自学Java的springboot框架,要用到定时推送消息.参考了网上的教程,自己调试,终于调好了.下面将网上的教程归纳下,总结复习下.  springboot开启定时任务  在SpringBo ...

  9. (入门SpringBoot)SpringBoot结合定时任务task(十)

    SpringBoot整合定时任务task 使用注解EnableScheduling在启动类上. 定义@Component作为组件被容器扫描. 表达式生成地址:http://cron.qqe2.com ...

随机推荐

  1. JDK动态代理源码学习

    继上一篇博客设计模式之代理模式学习之后http://blog.csdn.net/u014427391/article/details/75115928,本博客介绍JDK动态代理的实现原理,学习一下JD ...

  2. php工作两年了。。。

    对于一个快要毕业的人来说,我相信大部分人都是迷茫的,我也一样但是迷茫的一塌糊涂完全不知道以后自己能干什么. 2014年底,某某培训机构来到学校进行招生.反正在对方的一阵忽悠之下我是蠢蠢欲动,但是当时的 ...

  3. 西电2017ACM网络赛

    #include<bits/stdc++.h> using namespace std; typedef long long LL; #define ms(a,x) memset(a,x, ...

  4. Ubuntu彻底删除/卸载mysql,php,apache

    一.卸载删除 mysql 1 sudo apt-get autoremove --purge mysql-server-5.02 sudo apt-get remove mysql-server3 s ...

  5. CloseHandle 函数--关闭一个句柄

    CloseHandle函数 来源:https://msdn.microsoft.com/en-us/library/windows/desktop/ms724211(v=vs.85).aspx 作用 ...

  6. CAP 介绍及使用【视频】

    前言 很多同学可能对于CAP这个项目想有更一步的了解,包括她的工作原理以及适用的场景,所以博主就准备了一场直播给他家讲解了一下,这个视频是直播的一个录像. 由于我这次直播本来是没有打算对外的,所以也是 ...

  7. (转)java.util.Scanner应用详解

    java.util.Scanner应用详解   java.util.Scanner是Java5的新特征,主要功能是简化文本扫描.这个类最实用的地方表现在获取控制台输入,其他的功能都很鸡肋,尽管Java ...

  8. 【MYSQL】主从库查看及搭建

    show slave status 查看从库信息  http://blog.csdn.net/lxpbs8851/article/details/7898716 搭建主从库   http://www. ...

  9. 3.如何安装Apache Spark

    如何安装Apache Spark 1 Why Apache Spark 2 关于Apache Spark 3 如何安装Apache Spark 4 Apache Spark的工作原理 5 spark弹 ...

  10. javaBean与Servlet学习

    1.JavaBean JavaBean将java代码单独封装成了一个处理某种业务逻辑的类,可以降低HTML与Java代码的耦合度,并且简化JSP页面,提高Java程序代码的重用性及灵活性. JavaB ...