zoukankan      html  css  js  c++  java
  • 多线程-TaskExecutor-使用Demo

    BasicExecute.java
    package com.jef.executeTest;
    
    public abstract class BasicExecute extends Thread {
    
    
        @Override
        public void run() {
            commonRefresh();
        }
    
        /**
         * 共用方法调用
         */
        private void commonRefresh() {
    
        }
    
        public abstract void execute();
    }

    BasicEntity.java
    package com.jef.executeTest;
    
    public class BasicEntity {
        private Long id;
    
        private String name;
    
        public Long getId() {
            return id;
        }
    
        public void setId(Long id) {
            this.id = id;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    }
    FunctionExecute.java
    package com.jef.executeTest;
    
    
    public class FunctionExecute extends BasicExecute {
        private Long id;
        private String name;
    
        /**
         * 构造方法,业务参数传入
         * @param basicEntity
         */
        protected FunctionExecute(BasicEntity basicEntity) {
            id = basicEntity.getId();
            name = basicEntity.getName();
        }
    
        @Override
        public void execute() {
            syncBasicEntity(id, name);
        }
    
        /**
         * 业务流程
         */
        private void syncBasicEntity(Long id, String name) {
            // 这里面可能包含很多的业务操作
            System.out.println("id=" + id);
            System.out.println("name=" + name);
            System.out.println("execute test success");
        }
    
    }
    BasicExecuteTest.java
    package com.jef.executeTest;
    
    import org.springframework.core.task.TaskExecutor;
    
    public class BasicExecuteTest {
        private static TaskExecutor taskExecutor;
    
        public static void main(String[] args) {
            BasicEntity basicEntity = new BasicEntity();
            basicEntity.setId(1L);
            basicEntity.setName("Jef");
            taskExecutor.execute(new FunctionExecute(basicEntity));
        }
    }


  • 相关阅读:
    python基础4
    python的基础数据类型和编码
    python的if语句和while循环
    java特殊运算符
    深入理解java集合
    python常用模块
    python函数的参数问题
    集合关系之间的运算
    集合
    可变类型与不可变类型
  • 原文地址:https://www.cnblogs.com/tufujie/p/8353023.html
Copyright © 2011-2022 走看看