package com.callback;

public interface CSCallBack {
public void process(String status);
}
package com.callback;

public class Client implements CSCallBack {

  private Server server;

  public Client(Server server) {
this.server = server;
} public void sendMsg(final String msg){
System.out.println("客户端:发送的消息为:" + msg);
new Thread(new Runnable() {
@Override
public void run() {
server.getClientMsg(Client.this,msg);
}
}).start();
System.out.println("客户端:异步发送成功");
} @Override
public void process(String status) {
System.out.println("客户端:服务端回调状态为:" + status);
}
}
package com.callback;

public class Server {

  public void getClientMsg(CSCallBack csCallBack , String msg) {
System.out.println("服务端:服务端接收到客户端发送的消息为:" + msg); // 模拟服务端需要对数据处理
try {
Thread.sleep(5 * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("服务端:数据处理成功,返回成功状态 200");
String status = "200";
csCallBack.process(status);
}
}
package com.callback;

public class CallBackTest {
public static void main(String[] args) {
Server server = new Server();
Client client = new Client(server); client.sendMsg("Server,Hello~");
}
}

最新文章

  1. google protobuf安装与使用
  2. Selenium生成Report的利器- ExtentReports
  3. WPF 样式和行为
  4. mysql TRUNCATE
  5. ASP.NET中如何删除最近打开的项目和文件的记录
  6. oracle LogMiner配置使用
  7. How to install MP4box on CentOS 6
  8. 转载:JSONObject简介
  9. 创建XML文件
  10. 宣布发布 Windows Azure SDK 2.2,正式发布 Windows Azure Backup 和 Hyper-V 恢复管理器预览版
  11. Andrew Ng机器学习课程笔记--week3(逻辑回归&正则化参数)
  12. AtCoder Grand Contest 030 (AGC030) C - Coloring Torus 构造
  13. 图像特征的提取(gaussian,gabor,frangi,hessian,Morphology...)及将图片保存为txt文件
  14. ubuntu中的环境变量
  15. weblogic清除缓存
  16. java中Future与FutureTask使用与分析
  17. HTML中head与body标签
  18. java后台代码发送邮件
  19. 【Python学习笔记】Jupyter Lab目录插件安装
  20. 【线段树】【扫描线】Petrozavodsk Winter Training Camp 2018 Day 5: Grand Prix of Korea, Sunday, February 4, 2018 Problem A. Donut

热门文章

  1. Python协程之Gevent模块
  2. Shell基本语法---函数
  3. 题解 洛谷 P4098 【[HEOI2013]ALO 】
  4. 题解 洛谷 P6378 【[PA2010]Riddle】
  5. windows如何解决Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion'
  6. 使用queue 做一个分布式爬虫(一)
  7. web自动化 -- HTMLreport(三)测试报告输出log日志
  8. Java基础之java8新特性(1)Lambda
  9. NoSQL和SQL怎么选用?
  10. Python修改元组