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));
        }
    }


  • 相关阅读:
    flex 遍历Object或者JSON对象内容的实现代码
    Flex Vector使用(转)
    Flex——Array,ArrayCollection,Vector性能比较(转)
    SQLSERVER远程备份、恢复(转)
    隐藏Jquery dialog 按钮
    GSM 短信相关AT指令(转)
    SQL Server 父子迭代查询语句,树状查询(转)
    js framework comparation
    eventEmitter
    调试 shell script 方法
  • 原文地址:https://www.cnblogs.com/tufujie/p/8353023.html
Copyright © 2011-2022 走看看