20
Sep
Does Java have an answer to Node.js?
Java needs to do a couple of things easily to compete with Node.js which I believe will be the next killer web framework:
Unlike Node.js most Java frameworks are not written from the ground up to be asynchronous. Most asynchronous behavior in Java is accomplished through threads. For example all compliant Servlet Containers create 1 thread per request.
Threading like this does not scale but it particularly does not scale for the future of long running concurrent connections like HttpPush and Websocket. I believe long running concurrent connections are the future of web development.
So how do we get rid of the 1-thread-per-request? Event Driven Network IO! There are two libraries that do Event network IO: Grizzly and Netty. Purportedly Netty is better but Grizzly is more backward compatible with existing technologies. Some of the containers including Tomcat 7.0, Jetty, and Glassfish or any Servlet 3.0 support Websockets/HttpPush but it is extremely unclear what the threading policy is not to mention its only for these special types of requests. Remember Node.js is asynchronous for all requests and Java should be able to do likewise.
Making the network IO event driven only fixes part of the problem. We need to make the rest of the platform asynchronous but with out using lots of threads. Akka is the only library that I know that does this well.
So what is missing? Well we cannot use any libraries that use Servlet API or ThreadLocals. That eliminates many frameworks. For example Spring uses ThreadLocal to manage transactions among other things. Jersey also relies on ThreadLocals.
There is a microframework called Deft that looks very impressive and the Play framework is also working on this problem. However I would like something that builds on top of Jersey like Atmosphere does and perhaps reuses parts of the Servlet API. Basically Java is missing what Express is to Nodejs. Unfortunately there are just not many asynchronous Web Framework (URL routing, binding) options for Java right now.
If I had time I would look into making a Servlet API adapter to Netty along with extending Jersey. That would be a fun little project.
-
highlightsed liked this
-
promontoryop3 liked this
-
agentgt posted this