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


  • 相关阅读:
    pod
    jquery日历插件
    web前端常用api
    VUE.JS——脚手架安装
    github入门到上传本地项目
    appach修改默认端口之后数据库的访问
    在脚本中刷新impala元信息
    在脚本中刷新impala元信息
    不同hadoop集群之间迁移hive数据
    不同hadoop集群之间迁移hive数据
  • 原文地址:https://www.cnblogs.com/tufujie/p/8353023.html
Copyright © 2011-2022 走看看