• 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);
            }
        }
  • 相关阅读:
    maria-developers 开发者邮件
    Parallel Programming--perfbook
    面向对象设计模式中类与类关系
    binlog 轻松的找到没有及时提交的事物(infobin工具
    deeplearningbook-chinese
    Introduction to the Optimizer --cbo
    dell T420热插拔安装过程
    MySQL是如何利用索引的
    BTrace housemd TProfiler
    杨建荣的学习笔记
  • 原文地址:https://www.cnblogs.com/wwwcf1982603555/p/9090079.html
Copyright © 2020-2023  润新知