回调函数
Survive by day and develop by night.
talk for import biz , show your perfect code,full busy,skip hardness,make a better result,wait for change,challenge Survive.
happy for hardess to solve denpendies.
目录
概述
回调函数
需求:
设计思路
介绍 Java 实现回调的四种写法:
实现思路分析
1.反射;
public class Main {
public static void main(String[] args) throws Exception {
Request request = new Request();
System.out.println("[Main]:�ҿ����߳�ȥ�첽������");
new Thread(() -> {
try {
request.send(CallBack.class, CallBack.class.getMethod("processResponse"));
} catch (Exception e) {
e.printStackTrace();
}
}).start();
System.out.println("[Main]:�������ˣ���ȥ�ɵ���");
Thread.sleep(100000);
}
}
2.直接调用
public class Main2 {
public static void main(String[] args) throws Exception {
Request request = new Request();
System.out.println("[Main]:�ҿ����߳�ȥ�첽������");
CallBack callBack = new CallBack();
new Thread(() -> {
try {
request.send(callBack);
} catch (Exception e) {
e.printStackTrace();
}
}).start();
System.out.println("[Main]:�������ˣ���ȥ�ɵ���");
Thread.sleep(100000);
}
}
3.接口调用;
public class Main {
public static void main(String[] args) throws Exception {
Request request = new Request();
System.out.println("[Main]:�ҿ����߳�ȥ�첽������");
CallBack callBack = new CallBackImpl();
new Thread(() -> {
try {
request.send(callBack);
} catch (Exception e) {
e.printStackTrace();
}
}).start();
System.out.println("[Main]:�������ˣ���ȥ�ɵ���");
Thread.sleep(100000);
}
}
4.Lambda表达式。
public class Main {
public static void main(String[] args) throws Exception {
Request request = new Request();
System.out.println("[Main]:我开个线程去异步发请求");
new Thread(() -> {
try {
request.send(()-> System.out.println("[CallBack]:处理响应"));
} catch (Exception e) {
e.printStackTrace();
}
}).start();
System.out.println("[Main]:请求发完了,我去干点别的");
Thread.sleep(100000);
}
}
拓展实现
暂无:
性能参数测试:
1.功能测试
2.性能测试
这里主要是性能测试曲线,时间度量曲线测试:
3.高并发
接口的压力测试等
4.高可用的测试:
高可用的测试用工具。
参考资料和推荐阅读
- https://blog.csdn.net/AAA123524457/article/details/116019124
欢迎阅读,各位老铁,如果对你有帮助,点个赞加个关注呗!~