【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
浙公网安备 33010602011771号