netty权威指南学习笔记二——netty入门应用

2023-11-14

  经过了前面的NIO基础知识准备,我们已经对NIO有了较大了解,现在就进入netty的实际应用中来看看吧。重点体会整个过程。

按照权威指南写程序的过程中,发现一些问题:当我们在定义handler继承ChannelHanderAdapter时候,发现在其接口中没有可以实现的channelRead方法和channelReadComplete方法,然后查阅官网才发现netty5.0不见了,网上说是舍弃了,然后再看官网的一些例子,发现官网上继承的是ChannelInboundHandlerAdapter,当我将代码中handler的继承类更改为这个的时候发现前面的方法可以实现了。(同时发现ByteBuffer的一些方法调用不能调出书上的方法如readableBytes(),这个是我弄错了,ByteBuffer是jdk的包装类不是netty的,netty的应该用ByteBuf)为此将netty版本变更为

一、首先我们需要一个netty的环境,netty的环境搭建只需要一个netty的jar包即可。

  在maven工程中导入netty的jar资源

1 <dependency>
2             <groupId>io.netty</groupId>
3             <artifactId>netty-all</artifactId>
4             <!--<version>5.0.0.Alpha1</version>-->
5             <version>4.1.25.Final</version>
6         </dependency>

二、netty 服务端代码

TimeServer

 1 package com.netty.example;
 2 
 3 import io.netty.bootstrap.ServerBootstrap;
 4 import io.netty.channel.ChannelFuture;
 5 import io.netty.channel.ChannelInitializer;
 6 import io.netty.channel.ChannelOption;
 7 import io.netty.channel.EventLoopGroup;
 8 import io.netty.channel.nio.NioEventLoopGroup;
 9 import io.netty.channel.socket.SocketChannel;
10 import io.netty.channel.socket.nio.NioServerSocketChannel;
11 
12 public class TimeServer {
13     public void bind(int port){
14 //        创建接收任务的线程组和处理IO事件的线程组
15         EventLoopGroup boosGroup = new NioEventLoopGroup();
16         EventLoopGroup workGroup = new NioEventLoopGroup();
17         try {
18             ServerBootstrap bs = new ServerBootstrap();
19             bs.group(boosGroup,workGroup)
20                     .channel(NioServerSocketChannel.class)
21                     .option(ChannelOption.SO_BACKLOG,1024)
22                     .childHandler(new ChildChannelHandler());
23 //        绑定端口号,同步等待成功
24             ChannelFuture f = bs.bind(port).sync();
25 //        等待服务器监听端口关闭
26             f.channel().closeFuture().sync();
27         } catch (InterruptedException e) {
28             e.printStackTrace();
29         }finally {
30 //          优雅退出释放线程池资源
31             boosGroup.shutdownGracefully();
32             workGroup.shutdownGracefully();
33         }
34     }
35     public static void main(String[] args){
36         int port = 8080;
37         if(args!=null&&args.length>0){
38             port = Integer.valueOf(args[0]);
39         }
40         new TimeServer().bind(port);
41     }
42 
43 private  class ChildChannelHandler extends ChannelInitializer<SocketChannel>{
44     @Override
45     protected void initChannel(SocketChannel socketChannel) throws Exception {
46         socketChannel.pipeline().addLast(new TimeServerHandler());
47     }
48 
49 }
50 
51 }

TimeServerHandler

 1 package com.netty.example;
 2 
 3 import io.netty.buffer.ByteBuf;
 4 import io.netty.buffer.Unpooled;
 5 import io.netty.channel.ChannelHandlerContext;
 6 import io.netty.channel.ChannelInboundHandlerAdapter;
 7 
 8 import java.util.Date;
 9 
10 public class TimeServerHandler extends ChannelInboundHandlerAdapter {
11 
12 
13     @Override
14     public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
15         ByteBuf buf = (ByteBuf) msg;//将接收到的msg转换为netty的BytyBuf对象,注意区分jdk中的ByteBuffer
16         byte[] req = new byte[buf.readableBytes()];//创建接收缓冲区数据的字节数组
17         buf.readBytes(req);//将缓冲区的数据读取到字节数组中
18         String body = new String(req,"utf-8");//获取请求消息
19         System.out.println("The time server receive order:"+body);
20         String currentTime = "QUERY TIME ORDER".equalsIgnoreCase(body)?new Date(System.currentTimeMillis()).toString():"BAD ORDER";
21         ByteBuf resp = Unpooled.copiedBuffer(currentTime.getBytes());//将响应信息封装为netty 的ByteBuf对象,
22         ctx.write(resp);//异步发送应答消息给客户端
23     }
24 
25     @Override
26     public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
27         /*将消息发送队列中的消息写道SocketChannel中发送给对方。从性能上考虑,为了防止频繁唤醒Selector进行消息发送
28         * netty的write方法并不直接将消息写入socketChannel中,调用write方法只是把待发送的消息发送到数据缓冲数组中,
29         * 再通过调用flush()方法,将发送缓冲区中的消息全部写道SocketChannel中*/
30         ctx.flush();
31     }
32 
33     @Override
34     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
35         ctx.close();//发生异常时,关闭ChannelHandlerContext,释放ChannelHandlerContext相关联的句柄资源
36     }
37 }

三、netty 客户端代码

TimeClient

 1 package com.netty.example;
 2 
 3 import io.netty.bootstrap.Bootstrap;
 4 import io.netty.channel.ChannelFuture;
 5 import io.netty.channel.ChannelInitializer;
 6 import io.netty.channel.ChannelOption;
 7 import io.netty.channel.EventLoopGroup;
 8 import io.netty.channel.nio.NioEventLoopGroup;
 9 import io.netty.channel.socket.SocketChannel;
10 import io.netty.channel.socket.nio.NioSocketChannel;
11 
12 /*
13 * 客户端代码
14 * */
15 public class TimeClient {
16 //    配置客户端NIO线程
17     public void connection(String host,int port) {
18         EventLoopGroup group = new NioEventLoopGroup();
19         try {
20         Bootstrap bootstrap = new Bootstrap();
21         bootstrap.group(group)
22                 .channel(NioSocketChannel.class)
23                 .option(ChannelOption.TCP_NODELAY,true)
24                 .handler(new ChannelInitializer<SocketChannel>() {
25                     @Override
26                     protected void initChannel(SocketChannel socketChannel) throws Exception {
27                         socketChannel.pipeline().addLast(new TimeClientHandler());
28                     }
29                 });
30 //        发起异步连接操作
31         ChannelFuture f = bootstrap.connect(host,port).sync();
32 //        等待客户端链路关闭
33             f.channel().closeFuture().sync();
34         } catch (InterruptedException e) {
35             e.printStackTrace();
36         }finally{
37             group.shutdownGracefully();
38         }
39 
40     }
41     public static void main(String[] args){
42         int port = 8080;
43         if(args.length>0&&args!=null){
44            port = Integer.valueOf(args[0]);
45         }
46         new TimeClient().connection("127.0.0.1",port);
47     }
48 }

TimeClientHandler

 1 package com.netty.example;
 2 
 3 import io.netty.buffer.ByteBuf;
 4 import io.netty.buffer.Unpooled;
 5 import io.netty.channel.ChannelHandlerContext;
 6 import io.netty.channel.ChannelInboundHandlerAdapter;
 7 
 8 public class TimeClientHandler extends ChannelInboundHandlerAdapter {
 9     private final ByteBuf firstMsg;
10 
11     public TimeClientHandler() {
12         byte[] req = "QUERY TIME ORDER".getBytes();
13         firstMsg = Unpooled.buffer(req.length);
14         firstMsg.writeBytes(req);
15     }
16 
17     @Override
18     public void channelActive(ChannelHandlerContext ctx) throws Exception {
19     /*    当客户端和服务端TCP链路建立成功之后,Netty的NIO线程会调用channelActive方法,发送查询时间的指令给服务端,
20         调用ChannelHandlerContext的writeAndFlush方法将请求消息发送给服务端
21            当服务端返回应答消息时,channelRead()方法被调用*/
22         ctx.writeAndFlush(firstMsg);
23     }
24 
25     @Override
26     public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
27         ByteBuf buf = (ByteBuf) msg;
28         byte[] req = new byte[buf.readableBytes()];
29         buf.readBytes(req);
30         String body = new String(req,"utf-8");
31         System.out.println("Now is"+body);
32     }
33 
34     @Override
35     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
36         ctx.close();
37     }
38 }

四、启动运行

开启服务端

 1 D:\java\java1.8\jdk1.8\bin\java.exe "-javaagent:D:\我的软件\itSoft\IntelliJ IDEA\IntelliJ IDEA 2018.1.5\lib\idea_rt.jar=59255:D:\我的软件\itSoft\IntelliJ IDEA\IntelliJ IDEA 2018.1.5\bin" -Dfile.encoding=UTF-8 -classpath D:\java\java1.8\jdk1.8\jre\lib\charsets.jar;D:\java\java1.8\jdk1.8\jre\lib\deploy.jar;D:\java\java1.8\jdk1.8\jre\lib\ext\access-bridge-64.jar;D:\java\java1.8\jdk1.8\jre\lib\ext\cldrdata.jar;D:\java\java1.8\jdk1.8\jre\lib\ext\dnsns.jar;D:\java\java1.8\jdk1.8\jre\lib\ext\jaccess.jar;D:\java\java1.8\jdk1.8\jre\lib\ext\jfxrt.jar;D:\java\java1.8\jdk1.8\jre\lib\ext\localedata.jar;D:\java\java1.8\jdk1.8\jre\lib\ext\nashorn.jar;D:\java\java1.8\jdk1.8\jre\lib\ext\sunec.jar;D:\java\java1.8\jdk1.8\jre\lib\ext\sunjce_provider.jar;D:\java\java1.8\jdk1.8\jre\lib\ext\sunmscapi.jar;D:\java\java1.8\jdk1.8\jre\lib\ext\sunpkcs11.jar;D:\java\java1.8\jdk1.8\jre\lib\ext\zipfs.jar;D:\java\java1.8\jdk1.8\jre\lib\javaws.jar;D:\java\java1.8\jdk1.8\jre\lib\jce.jar;D:\java\java1.8\jdk1.8\jre\lib\jfr.jar;D:\java\java1.8\jdk1.8\jre\lib\jfxswt.jar;D:\java\java1.8\jdk1.8\jre\lib\jsse.jar;D:\java\java1.8\jdk1.8\jre\lib\management-agent.jar;D:\java\java1.8\jdk1.8\jre\lib\plugin.jar;D:\java\java1.8\jdk1.8\jre\lib\resources.jar;D:\java\java1.8\jdk1.8\jre\lib\rt.jar;D:\netty\target\classes;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter-data-redis\2.0.3.RELEASE\spring-boot-starter-data-redis-2.0.3.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter\2.0.3.RELEASE\spring-boot-starter-2.0.3.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot\2.0.3.RELEASE\spring-boot-2.0.3.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.0.3.RELEASE\spring-boot-autoconfigure-2.0.3.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.0.3.RELEASE\spring-boot-starter-logging-2.0.3.RELEASE.jar;C:\Users\litan\.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\litan\.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\Users\litan\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.10.0\log4j-to-slf4j-2.10.0.jar;C:\Users\litan\.m2\repository\org\apache\logging\log4j\log4j-api\2.10.0\log4j-api-2.10.0.jar;C:\Users\litan\.m2\repository\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;C:\Users\litan\.m2\repository\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;C:\Users\litan\.m2\repository\org\yaml\snakeyaml\1.19\snakeyaml-1.19.jar;C:\Users\litan\.m2\repository\org\springframework\data\spring-data-redis\2.0.8.RELEASE\spring-data-redis-2.0.8.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\data\spring-data-keyvalue\2.0.8.RELEASE\spring-data-keyvalue-2.0.8.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\data\spring-data-commons\2.0.8.RELEASE\spring-data-commons-2.0.8.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-tx\5.0.7.RELEASE\spring-tx-5.0.7.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-oxm\5.0.7.RELEASE\spring-oxm-5.0.7.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-aop\5.0.7.RELEASE\spring-aop-5.0.7.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-context-support\5.0.7.RELEASE\spring-context-support-5.0.7.RELEASE.jar;C:\Users\litan\.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\Users\litan\.m2\repository\io\lettuce\lettuce-core\5.0.4.RELEASE\lettuce-core-5.0.4.RELEASE.jar;C:\Users\litan\.m2\repository\io\projectreactor\reactor-core\3.1.8.RELEASE\reactor-core-3.1.8.RELEASE.jar;C:\Users\litan\.m2\repository\org\reactivestreams\reactive-streams\1.0.2\reactive-streams-1.0.2.jar;C:\Users\litan\.m2\repository\io\netty\netty-common\4.1.25.Final\netty-common-4.1.25.Final.jar;C:\Users\litan\.m2\repository\io\netty\netty-transport\4.1.25.Final\netty-transport-4.1.25.Final.jar;C:\Users\litan\.m2\repository\io\netty\netty-buffer\4.1.25.Final\netty-buffer-4.1.25.Final.jar;C:\Users\litan\.m2\repository\io\netty\netty-resolver\4.1.25.Final\netty-resolver-4.1.25.Final.jar;C:\Users\litan\.m2\repository\io\netty\netty-handler\4.1.25.Final\netty-handler-4.1.25.Final.jar;C:\Users\litan\.m2\repository\io\netty\netty-codec\4.1.25.Final\netty-codec-4.1.25.Final.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.0.3.RELEASE\spring-boot-starter-web-2.0.3.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.0.3.RELEASE\spring-boot-starter-json-2.0.3.RELEASE.jar;C:\Users\litan\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.9.6\jackson-databind-2.9.6.jar;C:\Users\litan\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;C:\Users\litan\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.9.6\jackson-core-2.9.6.jar;C:\Users\litan\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.6\jackson-datatype-jdk8-2.9.6.jar;C:\Users\litan\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.6\jackson-datatype-jsr310-2.9.6.jar;C:\Users\litan\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.6\jackson-module-parameter-names-2.9.6.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.0.3.RELEASE\spring-boot-starter-tomcat-2.0.3.RELEASE.jar;C:\Users\litan\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\8.5.31\tomcat-embed-core-8.5.31.jar;C:\Users\litan\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\8.5.31\tomcat-embed-el-8.5.31.jar;C:\Users\litan\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\8.5.31\tomcat-embed-websocket-8.5.31.jar;C:\Users\litan\.m2\repository\org\hibernate\validator\hibernate-validator\6.0.10.Final\hibernate-validator-6.0.10.Final.jar;C:\Users\litan\.m2\repository\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;C:\Users\litan\.m2\repository\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;C:\Users\litan\.m2\repository\com\fasterxml\classmate\1.3.4\classmate-1.3.4.jar;C:\Users\litan\.m2\repository\org\springframework\spring-web\5.0.7.RELEASE\spring-web-5.0.7.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-beans\5.0.7.RELEASE\spring-beans-5.0.7.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-webmvc\5.0.7.RELEASE\spring-webmvc-5.0.7.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-context\5.0.7.RELEASE\spring-context-5.0.7.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-expression\5.0.7.RELEASE\spring-expression-5.0.7.RELEASE.jar;C:\Users\litan\.m2\repository\mysql\mysql-connector-java\5.1.46\mysql-connector-java-5.1.46.jar;C:\Users\litan\.m2\repository\org\springframework\spring-core\5.0.7.RELEASE\spring-core-5.0.7.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-jcl\5.0.7.RELEASE\spring-jcl-5.0.7.RELEASE.jar;C:\Users\litan\.m2\repository\io\netty\netty-all\4.1.25.Final\netty-all-4.1.25.Final.jar com.netty.example.TimeServer
 2 22:06:36.427 [main] DEBUG io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework
 3 22:06:36.462 [main] DEBUG io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8
 4 22:06:36.509 [main] DEBUG io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false
 5 22:06:36.509 [main] DEBUG io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512
 6 22:06:36.556 [main] DEBUG io.netty.util.internal.PlatformDependent - Platform: Windows
 7 22:06:36.562 [main] DEBUG io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false
 8 22:06:36.563 [main] DEBUG io.netty.util.internal.PlatformDependent0 - Java version: 8
 9 22:06:36.567 [main] DEBUG io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available
10 22:06:36.568 [main] DEBUG io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available
11 22:06:36.569 [main] DEBUG io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available
12 22:06:36.570 [main] DEBUG io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available
13 22:06:36.571 [main] DEBUG io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true
14 22:06:36.571 [main] DEBUG io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9
15 22:06:36.571 [main] DEBUG io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.<init>(long, int): available
16 22:06:36.571 [main] DEBUG io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available
17 22:06:36.573 [main] DEBUG io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\litan\AppData\Local\Temp (java.io.tmpdir)
18 22:06:36.575 [main] DEBUG io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model)
19 22:06:36.577 [main] DEBUG io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false
20 22:06:36.577 [main] DEBUG io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1890582528 bytes
21 22:06:36.577 [main] DEBUG io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1
22 22:06:36.581 [main] DEBUG io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available
23 22:06:36.595 [main] DEBUG io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available
24 22:06:37.179 [main] DEBUG io.netty.channel.DefaultChannelId - -Dio.netty.processId: 14124 (auto-detected)
25 22:06:37.186 [main] DEBUG io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false
26 22:06:37.186 [main] DEBUG io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false
27 22:06:37.538 [main] DEBUG io.netty.util.NetUtil - Loopback interface: lo (Software Loopback Interface 1, 127.0.0.1)
28 22:06:37.540 [main] DEBUG io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200
29 22:06:38.027 [main] DEBUG io.netty.channel.DefaultChannelId - -Dio.netty.machineId: 00:50:56:ff:fe:c0:00:01 (auto-detected)
30 22:06:38.038 [main] DEBUG io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024
31 22:06:38.038 [main] DEBUG io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096
32 22:06:38.090 [main] DEBUG io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple
33 22:06:38.091 [main] DEBUG io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4
34 22:06:38.144 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8
35 22:06:38.145 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8
36 22:06:38.145 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192
37 22:06:38.145 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11
38 22:06:38.145 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216
39 22:06:38.145 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512
40 22:06:38.145 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256
41 22:06:38.145 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64
42 22:06:38.145 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768
43 22:06:38.145 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192
44 22:06:38.145 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true
45 22:06:38.159 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled
46 22:06:38.159 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0
47 22:06:38.159 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384

客户端运行后

 1 D:\java\java1.8\jdk1.8\bin\java.exe "-javaagent:D:\我的软件\itSoft\IntelliJ IDEA\IntelliJ IDEA 2018.1.5\lib\idea_rt.jar=59302:D:\我的软件\itSoft\IntelliJ IDEA\IntelliJ IDEA 2018.1.5\bin" -Dfile.encoding=UTF-8 -classpath D:\java\java1.8\jdk1.8\jre\lib\charsets.jar;D:\java\java1.8\jdk1.8\jre\lib\deploy.jar;D:\java\java1.8\jdk1.8\jre\lib\ext\access-bridge-64.jar;D:\java\java1.8\jdk1.8\jre\lib\ext\cldrdata.jar;D:\java\java1.8\jdk1.8\jre\lib\ext\dnsns.jar;D:\java\java1.8\jdk1.8\jre\lib\ext\jaccess.jar;D:\java\java1.8\jdk1.8\jre\lib\ext\jfxrt.jar;D:\java\java1.8\jdk1.8\jre\lib\ext\localedata.jar;D:\java\java1.8\jdk1.8\jre\lib\ext\nashorn.jar;D:\java\java1.8\jdk1.8\jre\lib\ext\sunec.jar;D:\java\java1.8\jdk1.8\jre\lib\ext\sunjce_provider.jar;D:\java\java1.8\jdk1.8\jre\lib\ext\sunmscapi.jar;D:\java\java1.8\jdk1.8\jre\lib\ext\sunpkcs11.jar;D:\java\java1.8\jdk1.8\jre\lib\ext\zipfs.jar;D:\java\java1.8\jdk1.8\jre\lib\javaws.jar;D:\java\java1.8\jdk1.8\jre\lib\jce.jar;D:\java\java1.8\jdk1.8\jre\lib\jfr.jar;D:\java\java1.8\jdk1.8\jre\lib\jfxswt.jar;D:\java\java1.8\jdk1.8\jre\lib\jsse.jar;D:\java\java1.8\jdk1.8\jre\lib\management-agent.jar;D:\java\java1.8\jdk1.8\jre\lib\plugin.jar;D:\java\java1.8\jdk1.8\jre\lib\resources.jar;D:\java\java1.8\jdk1.8\jre\lib\rt.jar;D:\netty\target\classes;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter-data-redis\2.0.3.RELEASE\spring-boot-starter-data-redis-2.0.3.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter\2.0.3.RELEASE\spring-boot-starter-2.0.3.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot\2.0.3.RELEASE\spring-boot-2.0.3.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.0.3.RELEASE\spring-boot-autoconfigure-2.0.3.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.0.3.RELEASE\spring-boot-starter-logging-2.0.3.RELEASE.jar;C:\Users\litan\.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\litan\.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\Users\litan\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.10.0\log4j-to-slf4j-2.10.0.jar;C:\Users\litan\.m2\repository\org\apache\logging\log4j\log4j-api\2.10.0\log4j-api-2.10.0.jar;C:\Users\litan\.m2\repository\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;C:\Users\litan\.m2\repository\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;C:\Users\litan\.m2\repository\org\yaml\snakeyaml\1.19\snakeyaml-1.19.jar;C:\Users\litan\.m2\repository\org\springframework\data\spring-data-redis\2.0.8.RELEASE\spring-data-redis-2.0.8.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\data\spring-data-keyvalue\2.0.8.RELEASE\spring-data-keyvalue-2.0.8.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\data\spring-data-commons\2.0.8.RELEASE\spring-data-commons-2.0.8.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-tx\5.0.7.RELEASE\spring-tx-5.0.7.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-oxm\5.0.7.RELEASE\spring-oxm-5.0.7.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-aop\5.0.7.RELEASE\spring-aop-5.0.7.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-context-support\5.0.7.RELEASE\spring-context-support-5.0.7.RELEASE.jar;C:\Users\litan\.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\Users\litan\.m2\repository\io\lettuce\lettuce-core\5.0.4.RELEASE\lettuce-core-5.0.4.RELEASE.jar;C:\Users\litan\.m2\repository\io\projectreactor\reactor-core\3.1.8.RELEASE\reactor-core-3.1.8.RELEASE.jar;C:\Users\litan\.m2\repository\org\reactivestreams\reactive-streams\1.0.2\reactive-streams-1.0.2.jar;C:\Users\litan\.m2\repository\io\netty\netty-common\4.1.25.Final\netty-common-4.1.25.Final.jar;C:\Users\litan\.m2\repository\io\netty\netty-transport\4.1.25.Final\netty-transport-4.1.25.Final.jar;C:\Users\litan\.m2\repository\io\netty\netty-buffer\4.1.25.Final\netty-buffer-4.1.25.Final.jar;C:\Users\litan\.m2\repository\io\netty\netty-resolver\4.1.25.Final\netty-resolver-4.1.25.Final.jar;C:\Users\litan\.m2\repository\io\netty\netty-handler\4.1.25.Final\netty-handler-4.1.25.Final.jar;C:\Users\litan\.m2\repository\io\netty\netty-codec\4.1.25.Final\netty-codec-4.1.25.Final.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.0.3.RELEASE\spring-boot-starter-web-2.0.3.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.0.3.RELEASE\spring-boot-starter-json-2.0.3.RELEASE.jar;C:\Users\litan\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.9.6\jackson-databind-2.9.6.jar;C:\Users\litan\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;C:\Users\litan\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.9.6\jackson-core-2.9.6.jar;C:\Users\litan\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.6\jackson-datatype-jdk8-2.9.6.jar;C:\Users\litan\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.6\jackson-datatype-jsr310-2.9.6.jar;C:\Users\litan\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.6\jackson-module-parameter-names-2.9.6.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.0.3.RELEASE\spring-boot-starter-tomcat-2.0.3.RELEASE.jar;C:\Users\litan\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\8.5.31\tomcat-embed-core-8.5.31.jar;C:\Users\litan\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\8.5.31\tomcat-embed-el-8.5.31.jar;C:\Users\litan\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\8.5.31\tomcat-embed-websocket-8.5.31.jar;C:\Users\litan\.m2\repository\org\hibernate\validator\hibernate-validator\6.0.10.Final\hibernate-validator-6.0.10.Final.jar;C:\Users\litan\.m2\repository\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;C:\Users\litan\.m2\repository\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;C:\Users\litan\.m2\repository\com\fasterxml\classmate\1.3.4\classmate-1.3.4.jar;C:\Users\litan\.m2\repository\org\springframework\spring-web\5.0.7.RELEASE\spring-web-5.0.7.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-beans\5.0.7.RELEASE\spring-beans-5.0.7.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-webmvc\5.0.7.RELEASE\spring-webmvc-5.0.7.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-context\5.0.7.RELEASE\spring-context-5.0.7.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-expression\5.0.7.RELEASE\spring-expression-5.0.7.RELEASE.jar;C:\Users\litan\.m2\repository\mysql\mysql-connector-java\5.1.46\mysql-connector-java-5.1.46.jar;C:\Users\litan\.m2\repository\org\springframework\spring-core\5.0.7.RELEASE\spring-core-5.0.7.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-jcl\5.0.7.RELEASE\spring-jcl-5.0.7.RELEASE.jar;C:\Users\litan\.m2\repository\io\netty\netty-all\4.1.25.Final\netty-all-4.1.25.Final.jar com.netty.example.TimeClient
 2 22:07:35.228 [main] DEBUG io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework
 3 22:07:35.273 [main] DEBUG io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8
 4 22:07:35.329 [main] DEBUG io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false
 5 22:07:35.329 [main] DEBUG io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512
 6 22:07:35.387 [main] DEBUG io.netty.util.internal.PlatformDependent - Platform: Windows
 7 22:07:35.390 [main] DEBUG io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false
 8 22:07:35.390 [main] DEBUG io.netty.util.internal.PlatformDependent0 - Java version: 8
 9 22:07:35.393 [main] DEBUG io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available
10 22:07:35.394 [main] DEBUG io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available
11 22:07:35.395 [main] DEBUG io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available
12 22:07:35.396 [main] DEBUG io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available
13 22:07:35.397 [main] DEBUG io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true
14 22:07:35.397 [main] DEBUG io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9
15 22:07:35.397 [main] DEBUG io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.<init>(long, int): available
16 22:07:35.397 [main] DEBUG io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available
17 22:07:35.398 [main] DEBUG io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\litan\AppData\Local\Temp (java.io.tmpdir)
18 22:07:35.398 [main] DEBUG io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model)
19 22:07:35.400 [main] DEBUG io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false
20 22:07:35.400 [main] DEBUG io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1890582528 bytes
21 22:07:35.400 [main] DEBUG io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1
22 22:07:35.401 [main] DEBUG io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available
23 22:07:35.420 [main] DEBUG io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available
24 22:07:36.030 [main] DEBUG io.netty.channel.DefaultChannelId - -Dio.netty.processId: 18472 (auto-detected)
25 22:07:36.032 [main] DEBUG io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false
26 22:07:36.033 [main] DEBUG io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false
27 22:07:36.324 [main] DEBUG io.netty.util.NetUtil - Loopback interface: lo (Software Loopback Interface 1, 127.0.0.1)
28 22:07:36.325 [main] DEBUG io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200
29 22:07:36.895 [main] DEBUG io.netty.channel.DefaultChannelId - -Dio.netty.machineId: 00:50:56:ff:fe:c0:00:01 (auto-detected)
30 22:07:36.905 [main] DEBUG io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024
31 22:07:36.905 [main] DEBUG io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096
32 22:07:36.938 [main] DEBUG io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple
33 22:07:36.938 [main] DEBUG io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4
34 22:07:36.992 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8
35 22:07:36.992 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8
36 22:07:36.992 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192
37 22:07:36.992 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11
38 22:07:36.992 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216
39 22:07:36.992 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512
40 22:07:36.992 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256
41 22:07:36.992 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64
42 22:07:36.992 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768
43 22:07:36.992 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192
44 22:07:36.992 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true
45 22:07:37.029 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled
46 22:07:37.029 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0
47 22:07:37.029 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384
48 22:07:37.080 [nioEventLoopGroup-2-1] DEBUG io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.bytebuf.checkAccessible: true
49 22:07:37.084 [nioEventLoopGroup-2-1] DEBUG io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@75655d17
50 22:07:37.126 [nioEventLoopGroup-2-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096
51 22:07:37.126 [nioEventLoopGroup-2-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2
52 22:07:37.126 [nioEventLoopGroup-2-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16
53 22:07:37.126 [nioEventLoopGroup-2-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8
54 Now isMon Jul 16 22:07:37 CST 2018

上面客户端最后一行是收到的服务端的应答,此时的服务端也出现了收到消息的语句,最后部分代码如下(重点是最后一行的请求消息):

1 22:06:38.159 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384
2 22:07:37.160 [nioEventLoopGroup-3-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096
3 22:07:37.160 [nioEventLoopGroup-3-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2
4 22:07:37.160 [nioEventLoopGroup-3-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16
5 22:07:37.160 [nioEventLoopGroup-3-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8
6 22:07:37.176 [nioEventLoopGroup-3-1] DEBUG io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.bytebuf.checkAccessible: true
7 22:07:37.179 [nioEventLoopGroup-3-1] DEBUG io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@164ea267
8 The time server receive order:QUERY TIME ORDER

运行OK!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

netty权威指南学习笔记二——netty入门应用 的相关文章

  • Java 中等效的并行扩展

    我在 Net 开发中使用并行扩展有一些经验 但我正在考虑在 Java 中做一些工作 这些工作将受益于易于使用的并行库 JVM 是否提供任何与并行扩展类似的工具 您应该熟悉java util concurrent http java sun
  • 在 Java 中连接和使用 Cassandra

    我已经阅读了一些关于 Cassandra 是什么以及它可以做什么的教程 但我的问题是如何在 Java 中与 Cassandra 交互 教程会很好 如果可能的话 有人可以告诉我是否应该使用 Thrift 还是 Hector 哪一个更好以及为什
  • Java中反射是如何实现的?

    Java 7 语言规范很早就指出 本规范没有详细描述反射 我只是想知道 反射在Java中是如何实现的 我不是问它是如何使用的 我知道可能没有我正在寻找的具体答案 但任何信息将不胜感激 我在 Stackoverflow 上发现了这个 关于 C
  • 在画布上绘图

    我正在编写一个 Android 应用程序 它可以在视图的 onDraw 事件上直接绘制到画布上 我正在绘制一些涉及单独绘制每个像素的东西 为此我使用类似的东西 for int x 0 x lt xMax x for int y 0 y lt
  • Java - 将节点添加到列表的末尾?

    这是我所拥有的 public class Node Object data Node next Node Object data Node next this data data this next next public Object g
  • 在 HTTPResponse Android 中跟踪重定向

    我需要遵循 HTTPost 给我的重定向 当我发出 HTTP post 并尝试读取响应时 我得到重定向页面 html 我怎样才能解决这个问题 代码 public void parseDoc final HttpParams params n
  • Final字段的线程安全

    假设我有一个 JavaBeanUser这是从另一个线程更新的 如下所示 public class A private final User user public A User user this user user public void
  • 列出jshell中所有活动的方法

    是否有任何命令可以打印当前 jshell 会话中所有新创建的方法 类似的东西 list但仅适用于方法 您正在寻找命令 methods all 它会打印所有方法 包括启动 JShell 时添加的方法 以及失败 被覆盖或删除的方法 对于您声明的
  • 磁模拟

    假设我在 n m 像素的 2D 表面上有 p 个节点 我希望这些节点相互吸引 使得它们相距越远吸引力就越强 但是 如果两个节点之间的距离 比如 d A B 小于某个阈值 比如 k 那么它们就会开始排斥 谁能让我开始编写一些关于如何随时间更新
  • Spring @RequestMapping 带有可选参数

    我的控制器在请求映射中存在可选参数的问题 请查看下面的控制器 GetMapping produces MediaType APPLICATION JSON VALUE public ResponseEntity
  • 斯坦福 NLP - 处理文件列表时 OpenIE 内存不足

    我正在尝试使用斯坦福 CoreNLP 中的 OpenIE 工具从多个文件中提取信息 当多个文件 而不是一个 传递到输入时 它会给出内存不足错误 All files have been queued awaiting termination
  • 如何在PreferenceActivity中添加工具栏

    我已经使用首选项创建了应用程序设置 但我注意到 我的 PreferenceActivity 中没有工具栏 如何将工具栏添加到我的 PreferenceActivity 中 My code 我的 pref xml
  • getResourceAsStream() 可以找到 jar 文件之外的文件吗?

    我正在开发一个应用程序 该应用程序使用一个加载配置文件的库 InputStream in getClass getResourceAsStream resource 然后我的应用程序打包在一个 jar文件 如果resource是在里面 ja
  • Eclipse Java 远程调试器通过 VPN 速度极慢

    我有时被迫离开办公室工作 这意味着我需要通过 VPN 进入我的实验室 我注意到在这种情况下使用 Eclipse 进行远程调试速度非常慢 速度慢到调试器需要 5 7 分钟才能连接到远程 jvm 连接后 每次单步执行断点 行可能需要 20 30
  • 仅将 char[] 的一部分复制到 String 中

    我有一个数组 char ch 我的问题如下 如何将 ch 2 到 ch 7 的值合并到字符串中 我想在不循环 char 数组的情况下实现这一点 有什么建议么 感谢您花时间回答我的问题 Use new String value offset
  • Java列表的线程安全

    我有一个列表 它将在线程安全上下文或非线程安全上下文中使用 究竟会是哪一个 无法提前确定 在这种特殊情况下 每当列表进入非线程安全上下文时 我都会使用它来包装它 Collections synchronizedList 但如果不进入非线程安
  • 声明的包“”与预期的包不匹配

    我可以编译并运行我的代码 但 VSCode 中始终显示错误 早些时候有一个弹出窗口 我不记得是什么了 我点击了 全局应用 从那以后一直是这样 Output is there but so is the error The declared
  • 捕获的图像分辨率太大

    我在做什么 我允许用户捕获图像 将其存储到 SD 卡中并上传到服务器 但捕获图像的分辨率为宽度 4608 像素和高度 2592 像素 现在我想要什么 如何在不影响质量的情况下获得小分辨率图像 例如我可以获取或设置捕获的图像分辨率为原始图像分
  • 使用 JMF 创建 RTP 流时出现问题

    我正处于一个项目的早期阶段 需要使用 RTP 广播DataStream创建自MediaLocation 我正在遵循一些示例代码 该代码目前在rptManager initalize localAddress 出现错误 无法打开本地数据端口
  • Spring Boot @ConfigurationProperties 不从环境中检索属性

    我正在使用 Spring Boot 1 2 1 并尝试创建一个 ConfigurationProperties带有验证的bean 如下所示 package com sampleapp import java net URL import j

随机推荐

  • 构建测试的体系化思维(高级篇)

    本文首发于个人网站 BY林子 转载请参考版权声明 00 引言 1 三个层次聊测试体系 测试人员缺乏体系化思维 新建产品团队或者新启项目 如何系统化地测试 组织级如何构建统一的测试体系 大家都接触过不计其数的测试 质量方面的文章或者培训课程
  • C++ Template

    引言 模板 Template 指C 程序设计设计语言中采用类型作为参数的程序设计 支持通用程序设计 C 的标准库提供许多有用的函数大多结合了模板的观念 如STL以及IO Stream 函数模板 在c 入门中 很多人会接触swap int i
  • android 手势检测(左右滑动、上下滑动)

    开发十年 就只剩下这套Java开发体系了 gt gt gt GestureDetector类可以让我们快速的处理手势事件 如点击 滑动等 使用GestureDetector分三步 1 定义GestureDetector类 2 初始化手势类
  • 共轭方式怎么判断_怎么判断共轭效应是吸电子共轭效应还是给电子共轭效应?吸电子基和给电子基是根据什么判断的?...

    谢邀 我想按照我的思路给你解答解答 我要祭出我的高等有机化学笔记了 先说一句 要笔记的 在老家放着 没法卖给你们 而且说实话不好好看书的人 给你笔记你也不会 共轭效应只是众多电子效应中的一种 先从共轭效应开始讲起吧 共轭效应是由于共轭体系的
  • 滤波器相位补偿

    概要 滤波器使用的过程中都会产生相位的改变 有时 相位的改变并不是我们想要的 例如 笔者在做Dolby Atmos的bass management的时候 希望将顶置的低频成分分割到左右通道或环绕通道 因为相位的缘故 叠加之前 左右通道或环绕
  • windows

    1 准备工作 准备U盘 格式化U盘 注意选择格式化的文件系统 可以鼠标右键C盘查看 然后将U盘格式化 好像是跟电脑引导模式相关UEFI gt NTFS 如果格式化的时候没有选对文件系统 那么在BIOS界面可能无法识别到U盘 进入官网下载制作
  • 04_kibana 7.4.2 安装和配置指南

    本文大纲 1 Kibana 的下载方式 1 官网直接下载 2 Linux 服务器直接下载 需要能够访问互联网的服务器 2 修改配置 3 kibana 的关闭和重启 首先 值得高兴的是kibana7 x 已经有官方中文的啦 更加方便我们的开发
  • WebGL系列 - 裁剪空间矩阵优化

    该系列仅为记录自己的学习相关知识 以 2d 的顶点着色器为例
  • 模型评估相关参数学习

    training process loss accurancy val loss val accurancy testing process classification report label predict digits 8 labe
  • 【服务器】交换机带外管理和带内管理

    一 交换机的带外管理是什么 在带外管理模式中 网络的管理控制信息与用户网络的承载业务信息在不同的逻辑信道传送 带外管理最大的优势在于 当网络出现故障中断时数据传输和管理都可以正常进行 不同的物理通道传送管理控制信息和数据信息 两者完全独立
  • Activiti 学习(二)—— Activiti 流程定义和部署

    概述 在这一节 我们将创建一个 Activit 工作流 并启动这个流程 主要包含以下几个步骤 定义流程 按照 BPMN 的规范 使用流程定义工具 用流程符号把整个流程描述出来 部署流程 把画好的流程定义文件 加载到数据库中 生成表的数据 流
  • No module named 'numpy.core._multiarray_umath'

    导入tensorflow后遇到No module named numpy core multiarray umath 原因是numpy的当前版本过低 解决办法 更新numpy的版本 命令行输入 pip install i https pyp
  • java if oracle,JAVA使ORACLE 实现DROP TABLE IF EXISTS的功能

    JAVA使ORACLE 实现DROP TABLE IF EXISTS的功能 ORACLE没有MYSQL等数据库的DROP TABLE IF EXISTS 使用起来非常不便 删表还要求表必须存在 不存在则删表报错 太麻烦了 如果能实现其他数据
  • 学习Spring必学的Java基础知识(8)----国际化信息

    b size x large 引述 size b 要学习Spring框架的技术内幕 必须事先掌握一些基本的Java知识 正所谓 登高必自卑 涉远必自迩 以下几项Java知识和Spring框架息息相关 不可不学 我将通过一个系列分别介绍这些J
  • MySql 查询方法总结

    一 示例数据 dept表 emp表 二 查询方法 1 內连查询 a 隐式内连 select xxx from xxx where 条件 b 显示内连 select xxx from xxx inner jion xxx on 条件 2 外连
  • IDEA 接口方法不能跳转到实体类实现方法的问题

    IDEA 接口方法不能跳转到实体类实现方法的问题 问题描述 原因分析 解决方案 总结 问题描述 没有跳入到实体类实现方法的I 向下的箭头图标 原因分析 原因极大可能是因为编辑器自带的代码高亮工具 Syntaxhighlighte 失效 以下
  • 版本号对比 -- Python实现

    相同位数版本号大小比较 1 def abc str1 str2 2 if str1 or str2 3 print 输入包含空字符串 请重新输入 4 return 输入包含空字符串 请重新输入 5 elif str1 str2 6 prin
  • Unity3D项目输出到iOS设备体验

    很久以前就听说过这个软件个了 当时觉得有cocos2d就够用了 开发一般的手机游戏应该不成问题了 后来还学习了一下cocos3d 最近突然想看一下这个传说中的Unity3D 安装上之后 里边自带有一个demo 点了一下播放按键 发现这个de
  • 半监督结点分类

    3 半监督结点分类 我们已经介绍过了一个简单但是灵活的可在图上进行有效信息传播的模型f X A 现在我们可以回过头来看半监督结点分类的问题了 就像本文的介绍中所简要概述的那样 我们可以通过在数据集X和基础图结构的邻接矩阵A上调整来我们的模型
  • netty权威指南学习笔记二——netty入门应用

    经过了前面的NIO基础知识准备 我们已经对NIO有了较大了解 现在就进入netty的实际应用中来看看吧 重点体会整个过程 按照权威指南写程序的过程中 发现一些问题 当我们在定义handler继承ChannelHanderAdapter时候