Skip to content

Instantly share code, notes, and snippets.

@peijiehu
Last active September 21, 2017 00:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peijiehu/7b5b0b55c4bfcc840f8d73bd6a302886 to your computer and use it in GitHub Desktop.
Save peijiehu/7b5b0b55c4bfcc840f8d73bd6a302886 to your computer and use it in GitHub Desktop.

Jetty is a lightweight servlet container serves as both http server and application server(similar to Tomcat, but lighter), easy to embed within a java application, there is an easy to use jetty client also.

Netty is an asynchronous event-driven network application framework. You can write your own servlet container or http client app with help of the Netty framework for example. It's a transport layer, not limited to http like Jetty is.

HTTP client non-blocking, asynchronous APIs are perfectly suited for large content downloads, for parallel processing of requests/responses and in cases where performance and efficient thread and resource utilization is a key factor.

Threads are relatively expensive resources in an operating system. Each thread needs memory for the stack (which can be for example 2 MB in size). When you create thousands of threads, this is going to cost a lot of memory; also, operating systems have limits on the number of threads that can be created. So you don't want to start a new thread for each accepted connection. The idea of asynchronous I/O is to decouple the threads from the connections (no one-to-one relation). There can be many more connections than threads, and whenever some event happens on one of the connections (for example, data is received), a thread from a thread pool is temporarily used to handle the event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment