轻量级RPC_java rpc 轻量级-程序员宅基地

技术标签: java基础  

一、RPC原理

  1. 什么是RPC
    RPC(Remote Procedure Call Protocol)——远程过程调用协议,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议。RPC协议假定某些传输协议的存在,如TCP或UDP,为通信程序之间携带信息数据。在OSI网络通信模型中,RPC跨越了传输层和应用层。RPC使得开发包括网络分布式多程序在内的应用程序更加容易。
    RPC采用客户机/服务器模式。请求程序就是一个客户机,而服务提供程序就是一个服务器。首先,客户机调用进程发送一个有进程参数的调用信息到服务进程,然后等待应答信息。在服务器端,进程保持睡眠状态直到调用信息到达为止。当一个调用信息到达,服务器获得进程参数,计算结果,发送答复信息,然后等待下一个调用信息,最后,客户端调用进程接收答复信息,获得进程结果,然后调用执行继续进行。
    在这里插入图片描述
  2. RPC原理
    在这里插入图片描述
    运行时,一次客户机对服务器的RPC调用,其内部操作大致有如下十步:
    1.调用客户端句柄;执行传送参数
    2.调用本地系统内核发送网络消息
    3.消息传送到远程主机
    4.服务器句柄得到消息并取得参数
    5.执行远程过程
    6.执行的过程将结果返回服务器句柄
    7.服务器句柄返回结果,调用远程系统内核
    8.消息传回本地主机
    9.客户句柄由内核接收消息
    10.客户接收句柄返回的数据
    二、NIO基础
    1.简介
    nio 是New IO 的简称,在jdk1.4 里提供的新api 。Sun 官方标榜的特性如下: 为所有的原始类型提供(Buffer)缓存支持字符集编码解码解决方案Channel :一个新的原始I/O 抽象。 支持锁和内存映射文件的文件访问接口。 提供多路(non-bloking) 非阻塞式的高伸缩性网络I/O
    2.传统的I/O与NIO的区别
    使用传统的I/O程序读取文件内容, 并写入到另一个文件(或Socket), 如下程序:
    File.read(fileDesc, buf, len);
    Socket.send(socket, buf, len);
    会有较大的性能开销, 主要表现在一下两方面:
    ① 上下文切换(context switch), 此处有4次用户状态和内核状态的切换
    ② Buffer内存开销, 一个是应用程序buffer, 另一个是系统读取buffer以及socket buffer

    其运行示意图如下
    在这里插入图片描述
  1. 先将文件内容从磁盘中拷贝到操作系统buffer
  2. 再从操作系统buffer拷贝到程序应用buffer
  3. 从程序buffer拷贝到socket buffer
  4. 从socket buffer拷贝到协议引擎.

NIO技术省去了将操作系统的read buffer拷贝到程序的buffer, 以及从程序buffer拷贝到socket buffer的步骤, 直接将 read buffer 拷贝到 socket buffer. java 的 FileChannel.transferTo() 方法就是这样的实现, 这个实现是依赖于操作系统底层的sendFile()实现的.
publicvoid transferTo(long position, long count, WritableByteChannel target);
他的底层调用的是系统调用sendFile()方法
sendfile(int out_fd, int in_fd, off_t *offset, size_t count);如下图
在这里插入图片描述
NIO相比传统IO的优势不在于数据传送的速度,而是NIO采用轮询+注册的方式,避免的传统IO中获取连接及从socket中读取数据和发送数据时的阻塞情况。
在这里插入图片描述
三、netty中handler的执行顺序
Handler与Servlet中的filter很像,通过Handler可以完成通讯报文的解码编码、拦截指定的报文、统一对日志错误进行处理、统一对请求进行计数、控制Handler执行与否。一句话,没有它做不到的只有你想不到的。

Netty中的所有handler都实现自ChannelHandler接口。按照输出来分,分为ChannelInboundHandler、ChannelOutboundHandler两大类。ChannelInboundHandler对从客户端发往服务器的报文进行处理,一般用来执行解码、读取客户端数据、进行业务处理等;ChannelOutboundHandler对从服务器发往客户端的报文进行处理,一般用来进行编码、发送报文到客户端。

Netty中,可以注册多个handler。ChannelInboundHandler按照注册的先后顺序执行;ChannelOutboundHandler按照注册的先后顺序逆序执行,如下图所示,按照注册的先后顺序对Handler进行排序,request进入Netty后的执行顺序为:
在这里插入图片描述
①服务端

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * • 配置服务器功能,如线程、端口 • 实现服务器处理程序,它包含业务逻辑,决定当有一个请求连接或接收数据时该做什么
 */
public class EchoServer {
	private final int port;
	public EchoServer(int port) {
		this.port = port;
	}
	public void start() throws Exception {
		EventLoopGroup eventLoopGroup = null;
		try {
			//server端引导类
			ServerBootstrap serverBootstrap = new ServerBootstrap();
			//连接池处理数据
			eventLoopGroup = new NioEventLoopGroup();
			serverBootstrap.group(eventLoopGroup)
			.channel(NioServerSocketChannel.class)//指定通道类型为NioServerSocketChannel,一种异步模式,OIO阻塞模式为OioServerSocketChannel
			.localAddress("localhost",port)//设置InetSocketAddress让服务器监听某个端口已等待客户端连接。
			.childHandler(new ChannelInitializer<Channel>() {//设置childHandler执行所有的连接请求
				@Override
				protected void initChannel(Channel ch) throws Exception {
					// 注册两个InboundHandler,执行顺序为注册顺序,所以应该是InboundHandler1 InboundHandler2
					// 注册两个OutboundHandler,执行顺序为注册顺序的逆序,所以应该是OutboundHandler2 OutboundHandler1
					//注意:不能将OutboundHandler加载流水线list的最后,否则会导致只会执行到最后一个InboundHandler的地方其后的Handler将不再被执行。
					ch.pipeline().addLast(new EchoInHandler1());
					ch.pipeline().addLast(new EchoOutHandler1());
					ch.pipeline().addLast(new EchoOutHandler2()); 
					ch.pipeline().addLast(new EchoInHandler2());
				}
					});
			// 最后绑定服务器等待直到绑定完成,调用sync()方法会阻塞直到服务器完成绑定,然后服务器等待通道关闭,因为使用sync(),所以关闭操作也会被阻塞。
			ChannelFuture channelFuture = serverBootstrap.bind().sync();
			System.out.println("开始监听,端口为:" + channelFuture.channel().localAddress());
			channelFuture.channel().closeFuture().sync();
		} finally {
			eventLoopGroup.shutdownGracefully().sync();
		}
	}

	public static void main(String[] args) throws Exception {
		new EchoServer(20000).start();
	}
}
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import java.util.Date;

public class EchoInHandler1 extends ChannelInboundHandlerAdapter {

	@Override
	public void channelRead(ChannelHandlerContext ctx, Object msg)
			throws Exception {
		System.out.println("in1");
		 // 通知执行下一个InboundHandler
        ctx.fireChannelRead(msg);
	}

	@Override
	public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
        ctx.flush();//刷新后才将数据发出到SocketChannel
	}

	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
			throws Exception {
		cause.printStackTrace();
		ctx.close();
	}
}

public class EchoInHandler2 extends ChannelInboundHandlerAdapter {

	@Override
	public void channelRead(ChannelHandlerContext ctx, Object msg)
			throws Exception {
		System.out.println("in2");
        ByteBuf buf = (ByteBuf) msg;
        byte[] req = new byte[buf.readableBytes()];
        buf.readBytes(req);
        String body = new String(req, "UTF-8");
        System.out.println("接收客户端数据:" + body);
        //向客户端写数据
        System.out.println("server向client发送数据");
        String currentTime = new Date(System.currentTimeMillis()).toString();
        ByteBuf resp = Unpooled.copiedBuffer(currentTime.getBytes());
        ctx.write(resp);
	}

	@Override
	public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
        ctx.flush();//刷新后才将数据发出到SocketChannel
	}

	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
			throws Exception {
		cause.printStackTrace();
		ctx.close();
	}
}
import java.util.Date;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;

public class EchoOutHandler1 extends ChannelOutboundHandlerAdapter {
	@Override
    // 向client发送消息
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
        System.out.println("out1");
        /*System.out.println(msg);*/
        
        String currentTime = new Date(System.currentTimeMillis()).toString();
        ByteBuf resp = Unpooled.copiedBuffer(currentTime.getBytes());
        ctx.write(resp);
        ctx.flush();
       }
}

public class EchoOutHandler2 extends ChannelOutboundHandlerAdapter {

	 @Override
	    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
	        System.out.println("out2");
	        // 执行下一个OutboundHandler
	        /*System.out.println("at first..msg = "+msg);
	        msg = "hi newed in out2";*/
	        super.write(ctx, msg, promise);
	    }
}

②客户端

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import java.net.InetSocketAddress;
/**
 * • 连接服务器 • 写数据到服务器 • 等待接受服务器返回相同的数据 • 关闭连接
 */
public class EchoClient {

	private final String host;
	private final int port;

	public EchoClient(String host, int port) {
		this.host = host;
		this.port = port;
	}

	public void start() throws Exception {
		EventLoopGroup nioEventLoopGroup = null;
		try {
			// 客户端引导类
			Bootstrap bootstrap = new Bootstrap();
			// EventLoopGroup可以理解为是一个线程池,这个线程池用来处理连接、接受数据、发送数据
			nioEventLoopGroup = new NioEventLoopGroup();
			bootstrap.group(nioEventLoopGroup)//多线程处理
					.channel(NioSocketChannel.class)//指定通道类型为NioServerSocketChannel,一种异步模式,OIO阻塞模式为OioServerSocketChannel
					.remoteAddress(new InetSocketAddress(host, port))//地址
					.handler(new ChannelInitializer<SocketChannel>() {//业务处理类
								@Override
								protected void initChannel(SocketChannel ch)
										throws Exception {
									ch.pipeline().addLast(new EchoClientHandler());//注册handler
								}
							});
			// 链接服务器
			ChannelFuture channelFuture = bootstrap.connect().sync();
			channelFuture.channel().closeFuture().sync();
		} finally {
			nioEventLoopGroup.shutdownGracefully().sync();
		}
	}

	public static void main(String[] args) throws Exception {
		new EchoClient("localhost", 20000).start();
	}
}
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class EchoClientHandler extends SimpleChannelInboundHandler<ByteBuf> {
	// 客户端连接服务器后被调用
	@Override
	public void channelActive(ChannelHandlerContext ctx) throws Exception {
		System.out.println("客户端连接服务器,开始发送数据……");
		byte[] req = "QUERY TIME ORDER".getBytes();//消息
		ByteBuf firstMessage = Unpooled.buffer(req.length);//发送类
		firstMessage.writeBytes(req);//发送
		ctx.writeAndFlush(firstMessage);//flush
	}

	// • 从服务器接收到数据后调用
	@Override
	protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg)
			throws Exception {
		System.out.println("client 读取server数据..");
		// 服务端返回消息后
		ByteBuf buf = (ByteBuf) msg;
		byte[] req = new byte[buf.readableBytes()];
		buf.readBytes(req);
		String body = new String(req, "UTF-8");
		System.out.println("服务端数据为 :" + body);
	}

	// • 发生异常时被调用
	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
			throws Exception {
		System.out.println("client exceptionCaught..");
		// 释放资源
		ctx.close();
	}
}
在使用Handler的过程中,需要注意:
1、ChannelInboundHandler之间的传递,通过调用 ctx.fireChannelRead(msg) 实现;调用ctx.write(msg) 将传递到	ChannelOutboundHandler。在ChannelOutboundHandle之间传递信息调用super.write(ctx, msg, promise)实现;
2、ctx.write()方法执行后,需要调用flush()方法才能令它立即执行。
3、流水线pipeline中outhandler不能放在最后,否则不生效
4、Handler的消费处理放在最后一个处理。

四、Netty发送对象
Netty中,通讯的双方建立连接后,会把数据按照ByteBuf的方式进行传输,例如http协议中,就是通过HttpRequestDecoder对ByteBuf数据流进行处理,转换成http的对象。基于这个思路,我自定义一种通讯协议:Server和客户端直接传输java对象。

实现的原理是通过Encoder把java对象转换成ByteBuf流进行传输通过Decoder把ByteBuf转换成java对象进行处理,处理逻辑如下图所示:
在这里插入图片描述
①javabean

import java.io.Serializable;
public class Person implements Serializable {
	private static final long serialVersionUID = 1L;
	private String name;
	private String sex;
	private int age;

	public String toString() {
		return "name:" + name + " sex:" + sex + " age:" + age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}
}

②工具类

import io.netty.buffer.ByteBuf;

public class ByteBufToBytes {
	/**
	 * 将ByteBuf转换为byte[]
	 * @param datas
	 * @return
	 */
	public byte[] read(ByteBuf datas) {
		byte[] bytes = new byte[datas.readableBytes()];// 创建byte[]
		datas.readBytes(bytes);// 将ByteBuf转换为byte[]
		return bytes;
	}
}

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class ByteObjConverter {
	/**
	 * 使用IO的inputstream流将byte[]转换为object
	 */
	public static Object byteToObject(byte[] bytes) {
		Object obj = null;
		ByteArrayInputStream bi = new ByteArrayInputStream(bytes);
		ObjectInputStream oi = null;
		try {
			oi = new ObjectInputStream(bi);
			obj = oi.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				bi.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			try {
				oi.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return obj;
	}
	/**
	 * 使用IO的outputstream流将object转换为byte[]
	 * @param bytes
	 * @return
	 */
	public static byte[] objectToByte(Object obj) {
		byte[] bytes = null;
		ByteArrayOutputStream bo = new ByteArrayOutputStream();
		ObjectOutputStream oo = null;
		try {
			oo = new ObjectOutputStream(bo);
			oo.writeObject(obj);
			bytes = bo.toByteArray();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				bo.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			try {
				oo.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return bytes;
	}
}

③服务端

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
/**
 * • 配置服务器功能,如线程、端口 • 实现服务器处理程序,它包含业务逻辑,决定当有一个请求连接或接收数据时该做什么
 */
public class EchoServer {

	private final int port;

	public EchoServer(int port) {
		this.port = port;
	}

	public void start() throws Exception {
		EventLoopGroup eventLoopGroup = null;
		try {
			//创建ServerBootstrap实例来引导绑定和启动服务器
			ServerBootstrap serverBootstrap = new ServerBootstrap();
			//创建NioEventLoopGroup对象来处理事件,如接受新连接、接收数据、写数据等等
			eventLoopGroup = new NioEventLoopGroup();
			//指定通道类型为NioServerSocketChannel,一种异步模式,OIO阻塞模式为OioServerSocketChannel
			//设置InetSocketAddress让服务器监听某个端口已等待客户端连接。
			serverBootstrap.group(eventLoopGroup).channel(NioServerSocketChannel.class).localAddress("localhost",port)
			.childHandler(new ChannelInitializer<Channel>() {
				//设置childHandler执行所有的连接请求
				@Override
				protected void initChannel(Channel ch) throws Exception {
					//注册解码的handler
                    ch.pipeline().addLast(new PersonDecoder());  //IN1  反序列化
					//添加一个入站的handler到ChannelPipeline  
					ch.pipeline().addLast(new EchoServerHandler());   //IN2
				}
					});
			// 最后绑定服务器等待直到绑定完成,调用sync()方法会阻塞直到服务器完成绑定,然后服务器等待通道关闭,因为使用sync(),所以关闭操作也会被阻塞。
			ChannelFuture channelFuture = serverBootstrap.bind().sync();
			System.out.println("开始监听,端口为:" + channelFuture.channel().localAddress());
			channelFuture.channel().closeFuture().sync();
		} finally {
			eventLoopGroup.shutdownGracefully().sync();
		}
	}

	public static void main(String[] args) throws Exception {
		new EchoServer(20000).start();
	}
}
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import cn.itcast_03_netty.sendobject.bean.Person;

public class EchoServerHandler extends ChannelInboundHandlerAdapter {
	@Override
	public void channelRead(ChannelHandlerContext ctx, Object msg)
			throws Exception {
		Person person = (Person) msg;
        System.out.println(person.getName());
        System.out.println(person.getAge());
        System.out.println(person.getSex());
	}

	@Override
	public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
		System.out.println("server 读取数据完毕..");
        ctx.flush();//刷新后才将数据发出到SocketChannel
	}

	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
			throws Exception {
		cause.printStackTrace();
		ctx.close();
	}
}

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import java.util.List;
 /**
  * 反序列化
  * 将Byte[]转换为Object
  */
public class PersonDecoder extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    	//工具类:将ByteBuf转换为byte[]
        ByteBufToBytes read = new ByteBufToBytes();
        byte[] bytes = read.read(in);
        //工具类:将byte[]转换为object
        Object obj = ByteObjConverter.byteToObject(bytes);
        out.add(obj);
    }
}

④客户端

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import java.net.InetSocketAddress;

/**
 * • 连接服务器 • 写数据到服务器 • 等待接受服务器返回相同的数据 • 关闭连接
 */
public class EchoClient {
	private final String host;
	private final int port;

	public EchoClient(String host, int port) {
		this.host = host;
		this.port = port;
	}

	public void start() throws Exception {
		EventLoopGroup nioEventLoopGroup = null;
		try {
			// 创建Bootstrap对象用来引导启动客户端
			Bootstrap bootstrap = new Bootstrap();
			// 创建EventLoopGroup对象并设置到Bootstrap中,EventLoopGroup可以理解为是一个线程池,这个线程池用来处理连接、接受数据、发送数据
			nioEventLoopGroup = new NioEventLoopGroup();
			// 创建InetSocketAddress并设置到Bootstrap中,InetSocketAddress是指定连接的服务器地址
			bootstrap.group(nioEventLoopGroup)//
					.channel(NioSocketChannel.class)//
					.remoteAddress(new InetSocketAddress(host, port))//
					.handler(new ChannelInitializer<SocketChannel>() {//
								// 添加一个ChannelHandler,客户端成功连接服务器后就会被执行
								@Override
								protected void initChannel(SocketChannel ch)
										throws Exception {
									// 注册编码的handler
									ch.pipeline().addLast(new PersonEncoder());  //out
									//注册处理消息的handler
									ch.pipeline().addLast(new EchoClientHandler());   //in
								}
							});
			// • 调用Bootstrap.connect()来连接服务器
			ChannelFuture f = bootstrap.connect().sync();
			// • 最后关闭EventLoopGroup来释放资源
			f.channel().closeFuture().sync();
		} finally {
			nioEventLoopGroup.shutdownGracefully().sync();
		}
	}

	public static void main(String[] args) throws Exception {
		new EchoClient("localhost", 20000).start();
	}
}
 io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class EchoClientHandler extends SimpleChannelInboundHandler<ByteBuf> {
	// 客户端连接服务器后被调用
	@Override
	public void channelActive(ChannelHandlerContext ctx) throws Exception {
		 Person person = new Person();
	        person.setName("angelababy");
	        person.setSex("girl");
	        person.setAge(18);
	        ctx.write(person);
	        ctx.flush();
	}

	// • 从服务器接收到数据后调用
	@Override
	protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg)
			throws Exception {
		System.out.println("client 读取server数据..");
		// 服务端返回消息后
		ByteBuf buf = (ByteBuf) msg;
		byte[] req = new byte[buf.readableBytes()];
		buf.readBytes(req);
		String body = new String(req, "UTF-8");
		System.out.println("服务端数据为 :" + body);
	}

	// • 发生异常时被调用
	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
			throws Exception {
		System.out.println("client exceptionCaught..");
		// 释放资源
		ctx.close();
	}
}

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
 /**
  * 序列化
  * 将object转换成Byte[]
  */
public class PersonEncoder extends MessageToByteEncoder<Person> {
 
    @Override
    protected void encode(ChannelHandlerContext ctx, Person msg, ByteBuf out) throws Exception {
    	//工具类:将object转换为byte[]
        byte[] datas = ByteObjConverter.objectToByte(msg);
        out.writeBytes(datas);
        ctx.flush();
    }
}
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_43450987/article/details/88073831

智能推荐

使用docker部署nginx搭建简单的idea-2019 jrebel插件激活服务器_docker 激活服务器 intellij-程序员宅基地

文章浏览阅读759次。之前用的jrebel激活方式一直都是用的 *lanyus* 大神的 [jrebel激活](http://idea.lanyus.com)插件,但是需要一直开着命令行窗口,或者将jrebel调整成离线模式,心血来潮也想自己配置一个反向代理,代理到大神的网站上去_docker 激活服务器 intellij

1024: 计算字母序号_c语言1024计算字母序号-程序员宅基地

文章浏览阅读326次。输入一个英文字母(可能是大写,也可能是小写),输出该字母在字母表中的序号(’a’和’A’的序号为1)。输出一个整数,表示该字母在字母表的序号,输出单独占一行。输入只有一个英文字母。_c语言1024计算字母序号

浅拷贝与深拷贝-程序员宅基地

文章浏览阅读75次。目录 什么是浅拷贝 实现浅拷贝有哪些方法呢? 什么是深拷贝? 实现浅拷贝有哪些方法呢? 总结 什么是浅拷贝如果数据是基本数据类型,在浅拷贝的时候就如同于直接赋值,是拷贝其本身的值;但是如果除了基本数据类型之外还有一..._元素值传入通道(chan)时会被复制,这里是浅表复制还是深层复制?

小偷php杰奇小说源码_杰奇小说系统 v1.8-程序员宅基地

文章浏览阅读604次。杰奇1.8安装使用和更新说明一、1.8程序需要 php 5.3.x + zend guard loader + mysql 5.x二、安装程序还没整理,请手工导入install目录下的 struct.sql 和 data.sql,然后修改 /configs/define.php 设置正确数据库参数后登陆后台管理三、代理原创作品功能代理模式为:由杰奇书盟(book.jieqi.com)获取原创站共享..._杰奇1.8程序

《算法竞赛入门经典》——刘汝佳_刘汝佳.算法竞赛入门经典-程序员宅基地

文章浏览阅读2.7k次。“构造性”和“可行性”是计算机学科的两个最根本特征。比赛的核心是算法#1 语言篇编程不是看会的,也不是听会的,而是练会的,所以应尽量在计算机旁阅读书本,以便把书中的程序输入到计算机中进行调试,顺便再做做上机练习。千万不要图快—如果没有足够的时间来实践,那么学的快,忘得也快!1.1算数表达式原因并不重要,重要的是规范:根据规范做事情,则一切尽在掌握中。提示1-1:整数值用%d输出,实数用%f输出。提示1-2:整数/整数=整数,浮点数/浮点数=浮点数。整数-浮点数=浮点数。一般来说,._刘汝佳.算法竞赛入门经典

转:明茨伯格:组织不需要英雄,只需要有雅量的领导_明茨伯格 斯特德 答案-程序员宅基地

文章浏览阅读2.2k次。冥想,从自满中警醒出来,换个角度来重新考虑一些已经有固定答案的问题_明茨伯格 斯特德 答案

随便推点

python性能优化方案_6个Python性能优化技巧-程序员宅基地

文章浏览阅读1k次。ython是一门非常酷的语言,因为很少的Python代码可以在短时间内做很多事情,并且,Python很容易就能支持多任务和多重处理。Python的批评者声称Python性能低效、执行缓慢,但实际上并非如此:尝试以下6个小技巧,可以加快Python应用程序。1、关键代码可以依赖于扩展包Python使许多编程任务变得简单,但是对于很关键的任务并不总是提供最好的性能。使用C、C++或者机器语言扩展包来执..._python 性能调优

银河麒麟操作系统内存异常占用bug_麒麟系统aduit bug-程序员宅基地

文章浏览阅读681次。安装银河Kylin系统后,服务器内存,在没有任何服务的情况下,异常升高。_麒麟系统aduit bug

【目标检测】One-stage/Two-stage/Anchor Free_目标检测one-stage,two-stage,anchor-free对比-程序员宅基地

文章浏览阅读2.1k次。文章目录Two-stageOne-stageTwo-Stage和One-Stage方法的结合One-stage和Two-stage的比较Anchor-Freeanchor-free和anchor-based结合——Guided Anchoringhttps://www.zhihu.com/question/266143762/answer/304172590https://blog.csdn...._目标检测one-stage,two-stage,anchor-free对比

vue-router(路由)快速入门 浅析(适合vue小白)_用saber做登录界面-程序员宅基地

文章浏览阅读1.5k次。首先,由于博主学到vue的路由时是基于vue-cli3.0和webpack打包器进行开发的,所以,菜鸟教程和一些官方教程的案例好像并不适合(可能是自己刚学皮毛理解不够深),所以,博主进行了各种查阅,总算写出一个小案例,总结出如下知识点:Vue Router 是 Vue.js 官方的路由管理器。它和 Vue.js 的核心深度集成,让构建单页面应用变得易如反掌。包含的功能有:嵌套的路由/视图表..._用saber做登录界面

hihoCoder#1788 : 偶数长度回文子串_偶数回文子串-程序员宅基地

文章浏览阅读646次。时间限制:5000ms单点时限:1000ms内存限制:256MB描述给定一个小写字母字符串,请判断它是否有长度为偶数的非空连续回文子串输入输入包含多组数据。每组数据包含一行一个小写字母字符串 S1 ≤ |S| ≤ 105输出对于每组数据如果存在,输出YES,否则输出NO样例输入cabbadababa样例输出YESNO 分..._偶数回文子串

使用Jackon工具类完成字符串与List泛型互转替代fastjson_jackson 工具类 转list-程序员宅基地

文章浏览阅读1.3k次。fastjson最近出现漏洞,名为Fastjson反序列化漏洞2022年5月23日,fastjson 官方发布安全通报,fastjson _jackson 工具类 转list

推荐文章

热门文章

相关标签