【Java/线程】使用线程非阻塞调用外界接口的门面模式

【门面类】

package com.hy.lab.caller;

import javax.annotation.Resource;

/**
 * 使用线程非阻塞调用外界接口的门面模式
 * 优势:非阻塞、不因外界系统不可用而出异常,代码简单
 */
public class Facade {
    @Resource
    OuterSystem realOs;

    public void send(String signal){
        new Thread(()->{
            try{
                realOs.send(signal);
            }catch(Exception e){
                e.printStackTrace();
            }
        }).start();
    }
}

【外界系统模拟类】

package com.hy.lab.caller;

import org.springframework.stereotype.Service;

@Service
public class OuterSystem {
    public void send(String signal){
        // call other system
    }
}

END

posted @ 2022-07-20 20:25  逆火狂飙  阅读(40)  评论(0)    收藏  举报
生当作人杰 死亦为鬼雄 至今思项羽 不肯过江东