/** * Created by LiuHuiChao on 2016/11/15. * description:based on TCP/IP+NIO to deliver the message */ public class TCP_IP_NIO { @Test public void clientStart() throws IOException { SocketChannel channel=SocketChannel.open(); channel.configureBlockin…
最近看到阿里的一位童鞋写的一本关于分布式的书,感觉不错,准备把这本书上基础的代码都写一写. /** * Created by LiuHuiChao on 2016/11/15. * description:based on TCP/IP+BIO to deliver the message */ public class TCP_IP_BIO { /** * client端 * @throws IOException */ @Test public void startClient() thro…
Java代码(使用了2个内部类): package Threads; import java.util.LinkedList; /** * Created by Frank */ public class ProdCons { protected LinkedList<Object> list = new LinkedList<>(); protected int max; protected boolean done = false; public static void mai…
基于Java自身包实现消息方式的系统间通信的方式有:TCP/IP+BIO,TCP/IP+NIO,UDP/IP+BIO,UDP/IP+NIO.下面就这4种类型一一做个详细的介绍: 一.TCP/IP+BIO 在java中可基于Socket,ServerSocket来实现TCP/IP+BIO的系统间通信.Socket主要用于实现建立连接以及网络IO的操作,ServerSocket主要用于实现服务器端端口的监听及Socket对象的获取.基于Socket实现客户端的代码如下: public class C…