Create a ByteBuf in Netty 4.0

The documentation seems pretty clear to me: Creation of a buffer It is recommended to create a new buffer using the helper methods in Unpooled rather than calling an individual implementation’s constructor. Then in Unpooled, you’ve got options of wrapping or copying. For example: Unpooled.copiedBuffer(ByteBuffer) Unpooled.copiedBuffer(byte[]) Unpooled.wrappedBuffer(ByteBuffer) Unpooled.wrappedBuffer(byte[]) Choose whichever method is appropriate based on … Read more

Spring WebFlux differences when Netty vs. Tomcat is used under the hood

Currently there are 2 basic concepts to handle parallel access to a web-server with various advantages and disadvantages: Blocking Non-Blocking Blocking Web-Servers The first concept of blocking, multi-threaded server has a finite set amount of threads in a pool. Every request will get assigned to specific thread and this thread will be assigned until the … Read more

Benefits of Netty over basic ServerSocket server?

The main advantage of Netty over simply reading from and writing to sockets using streams is that Netty supports non-blocking, asynchronous I/O (using Java’s NIO API); when you use streams to read and write from sockets (and you start a new thread for each connected accepted from a ServerSocket) you are using blocking, synchronous I/O. … Read more

Use Jetty or Netty?

Jetty has had support for asynchronous request processing since version 6 (see here), using a proprietary API. More recent versions support the asynchronous API as part of the Servlet 3.0 API, like any other compliant implementation. Using Netty would seem like a lot of work for little gain, unless you have highly specific requirements. Otherwise, … Read more

What does ChannelOption.SO_BACKLOG do?

It’s a passed through socket option determining the number of connections queued. http://docs.oracle.com/javase/7/docs/api/java/net/ServerSocket.html The maximum queue length for incoming connection indications (a request to connect) is set to the backlog parameter. If a connection indication arrives when the queue is full, the connection is refused. More on netty channels: http://seeallhearall.blogspot.de/2012/06/netty-tutorial-part-15-on-channel.html

How Netty uses thread pools?

This is from NioServerSocketChannelFactory document A ServerSocketChannelFactory which creates a server-side NIO-based ServerSocketChannel. It utilizes the non-blocking I/O mode which was introduced with NIO to serve many number of concurrent connections efficiently. How threads work There are two types of threads in a NioServerSocketChannelFactory; one is boss thread and the other is worker thread. Boss … Read more

Netty- cannot access class jdk.internal.misc.Unsafe

To allow netty to access the class, start java with the following option: –add-opens java.base/jdk.internal.misc=ALL-UNNAMED This opens the package jdk.internal.misc in module java.base to the unamed module. See also the documentation for the java command, and this intro to the Java module system in general. EDIT: For Netty to use its direct buffer optimizations, you … Read more

When is “java.io.IOException:Connection reset by peer” thrown?

java.io.IOException: Connection reset by peer The other side has abruptly aborted the connection in midst of a transaction. That can have many causes which are not controllable from the server side on. E.g. the enduser decided to shutdown the client or change the server abruptly while still interacting with your server, or the client program … Read more