Here is a simple web Server Based on AIO. This is a simple example.
/*** A simple web server <br/> * enter localhost in the browser: 8080/access ** @ author Joeson * @ since 2014/05 **/public class AioServer implements Runnable {private AsynchronousChannelGroup asyncChannelGroup; private AsynchronousServerSocketChannel server; public AioServer (int port) throws Exception {// create a thread pool ExecutorService executor = Executors. newFixedThreadPool (20); // asynchronous channel manager asyncChannelGroup = AsynchronousChannelGroup. wi ThThreadPool (executor); // creates an asynchronous Socket for the server. This is short for server socket. // Asynchronous channel manager, which sets the server parameter server = AsynchronousServerSocketChannel. open (asyncChannelGroup ). bind (new InetSocketAddress (port);} public void run () {try {// specify the receiving operation object for the server socket. the accept prototype is: // accept (A attachment, CompletionHandler <AsynchronousSocketChannel ,//? Super A> handler) // that is, the type A parameter of CompletionHandler here is the first parameter actually used to call the accept method // that is, listener. Another parameter V is the client socketserver in the prototype. accept (server, new CompletionHandler <AsynchronousSocketChannel, AsynchronousServerSocketChannel> () {String str = "
The concurrency of web Servers Based on AIO is higher than that of NIO and Netty. This is mainly because the I/O processing model based on Proactor transfers read/write operations to the right operating system.
(Of course, the static page here is relatively small, saving time in transmission, but it will not have a great impact)
Server concurrency Based on Netty and nio can process more than 6-7 requests per second. However, if AIO is used, it can handle more than 9000 requests (marked by my machine ), tomcat is also a finished product of about 9000, all marked with the same static page.
I have to say that the asynchronous processing of AIO is still very powerful, but it may be worse than NIO in terms of Server Load balancer processing control.