zoukankan      html  css  js  c++  java
  • Spring注解定时任务

    xmlns:task="http://www.springframework.org/schema/task"
    
    xsi:schemaLocation="
                http://www.springframework.org/schema/task
                http://www.springframework.org/schema/task/spring-task-3.0.xsd
    
    
     <task:scheduler id="myScheduler" pool-size="5"/>  
        <task:annotation-driven scheduler="myScheduler"/> 
    
    
    实现定时任务
    @Scheduled(cron = "0/5 * * * * ?")
        public void login()throws Exception{
            System.out.println("王华");
        }
            

     实现异步

    @Async
        public void registerAsync(User user) throws Exception {
            SimpleDateFormat formate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String result1 = null;
            for (int i = 0; i < 3; i++) {
                result1 = ringMessage.register(user.getUserId(), user.getLoginPassword());
                if (result1.equals("success")) {
                    user.setEasemobStatus("1");
                    usersMapper.update(user);
                    break;
                }
            }
            // 用戶角色為商家註冊環信群組
            if (result1.equals("success") && !user.getRoleId().equals("500")) {
                String groupId = null;
                ArrayNode members = JsonNodeFactory.instance.arrayNode();
                for (int i = 0; i < 5; i++) {
                    groupId = ringMessage.createChatGroup("粉丝交流", "群组聊天", true, true, 200,
    
                            user.getUserId(), members);
                    if (!groupId.equals("error")) {
                        break;
                    }
                }
                // 注册群组时生成群组id
                String communityId = UUIDGenerator.getUUID();
                Community community = new Community();
                community.setRingGroupId(groupId);
                community.setOwnerId(user.getUserId());
                community.setMaxmenbernum("200");
                community.setCreateTime(formate.format(new Date()));
                community.setCName("粉丝交流");
                community.setCommunityId(communityId);
                communityMapper.insert(community);
            }
        }
  • 相关阅读:
    注解-案例
    注解(Annotation)
    适合新手看的超详细CentOS Linux 7 安装Tomcat8过程
    CentOS Linux 7 提示 lsof: 未找到命令
    解决MySql报错:1130
    Spring Boot 创建自定义的properties文件
    spring boot 使用Schedule创建轻量级定时任务
    4.Java数组模块
    3.IDEA开发工具
    2.java基础语法
  • 原文地址:https://www.cnblogs.com/wwwcf1982603555/p/9090079.html
Copyright © 2011-2022 走看看