@FunctionalInterface public interface Runnable { /** * When an object implementing interface <code>Runnable</code> is used * to create a thread, starting the thread causes the object's * <code>run</code> method to be called in that separately executing * thread. * <p> * The general contract of the method <code>run</code> is that it may * take any action whatsoever. * * @see java.lang.Thread#run() */ public abstract void run(); }
用接口实现的方式简化代码,使得每个方法闭环
public void A(Bean bean){
operateB(bean, () -> operateC(bean, () -> {
//业务逻辑
}));
}
private void operateB(Bean bean, Runnable nextStep){
//do pre 如分布式加锁操作
//执行下一步
nextStep.run();
//do after 如分布式释放操作
}
private void operateC(Bean bean, Runnable nextStep){
//do pre 如分布式加锁操作
//执行下一步
nextStep.run();
//do after 如分布式释放操作
}