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