• 定时任务

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

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. Java基础语法<十二> 泛型程序设计

    1 意义 泛型程序设计意味着编写的代码可以被很多不同类型的对象所重用. 常见应用 : ArrayList 2 K T V E ? object等的含义 类型变量使用大写形式 E – Element ( ...

  2. Domains域

    一个域是一个criteria(度量标准)列表,每个criterion(标准尺度)是一个三元列表或者元组:field_name,operator,value. field_name(str) 当前模型的 ...

  3. app耗电优化之二 使用电源管理来安排任务

    PowerManager 电源管理(电源使用管理).主要管理设备启动,保持活动,休眠,唤醒.其中为了保持任务,提供了PowerManager.WakeLock(唤醒锁).执行任务时持有这个唤醒锁,就可 ...

  4. nyoj_7:街区最短路径问题

    做这题时,先假设目标点在某个位置,然后对其稍微移动dx,dy,分析对ans的影响.最终得,选点时,使一半的横坐标比目标点横坐标小,一半的纵坐标比目标点小,这样得到的ans最小. 题目链接: http: ...

  5. Linux,activemq-cpp之消息过滤器

    假设过滤器字符串如下: filt1=aaaa filt2=bbbb filt3=cccc activeMQ-cpp中消息过滤器,在发送消息的producer.cpp中,对message进行属性设置,m ...

  6. 电脑装windows与Centos双系统时引导问题

    (本文对电脑如何装windows系统和centos系统不进行详细赘述.) 电脑装双系统时,首先要安装windows系统,在硬盘中划分一块空闲的分区,用来安装centos系统(可以借助"软碟通 ...

  7. 【PHP】数据类型转换

    PHP的数据类型转换属于强制转换,允许转换的PHP数据类型有: (int).(integer):转换成整形 (float).(double).(real):转换成浮点型 (string):转换成字符串 ...

  8. cin问题 分类: c++ 2014-08-02 21:13 38人阅读 评论(0) 收藏

    string s: while(cin>>s){ cout<<s<endl; } 当输入ss w    ww   w   w 按enter时 输出为 ss w ww w ...

  9. 初学Python(二)——数组

    初学Python(二)——数组 初学Python,主要整理一些学习到的知识点,这次是数组. # -*- coding:utf-8 -*- list = [2.0,3.0,4.0] #计算list长度 ...

  10. Android学习笔记- Fragment实例 底部导航栏的实现

    1.要实现的效果图以及工程目录结构: 先看看效果图吧: 接着看看我们的工程的目录结构: 2.实现流程: Step 1:写下底部选项的一些资源文件 我们从图上可以看到,我们底部的每一项点击的时候都有不同 ...