Site Archive (Complete)
Java Blog: What Do Java, a Grizzly, and Comet Have In Common?
Java
SWAINE'S CAFE

Black. No Sugar. Extra Caffeine.

by Mike Swaine
ERIC BRUNO'S BLOG

Java: The Daily Grind.

by Eric Bruno
August 03, 2006

What Do Java, a Grizzly, and Comet Have In Common?

Explore advanced Ajax programming in Java.

Comet programming is the name given to the pattern commonly used in Ajax web applications, where data is streamed asynchronously to the browser from a web server. It also describes the ability of the web server to continue to send data to the browser, even without a new request from the browser. This requires the web server to maintain client connections for very long periods of time. Doing this for many browsers is a resource-intense operation that does not scale well.

There are techniques you can use to help with scalability, but there are other issues, such as message reliability, that may otherwise require you to use an enterprise messaging system, such as a JMS provider. So much for lightweight web applications!

Fortunately, there are other solutions. For instance, Sun created an HTTP listener that uses Java NIO in a package called Grizzly. Grizzly was designed to work on top of the Apache Tomcat Coyote HTTP Connector, and has since been integrated into GlassFish and the Sun Java Application Server 8.1, Platform Edition. The blog I referenced above, by Jean-Francois Arcand, describes Grizzly, its design, and how it helps a Comet-based applications scale well.

Comet API

Recently, Jean-Francois Arcand blogged about the Comet API that has been created for Grizzly (and hence GlassFish), and works with any web server that supports asynchronous request processing (ARP). This includes Apache Jetty, Tomcat, and of course GlassFish. However, Comet support is fairly new and available only starting in GlassFish 9.1 ea-b10.

If you’re building Ajax-based applications, and you’re experiencing (or concerned you will experience) issues around scalability, you should check out Comet and Grizzly. The techniques used within, namely the use of Java NIO as opposed to individual threads per request, achieve the same asynchronous, event-based, behavior needed for Ajax, except without all of the overhead.

To further simplify your life of Ajax-induced JavaScript coding, check out jMaki, which enables you to use JavaScript in your Java-based applications as either a JSP tag library or a JSF component.

Posted by Eric Bruno at 09:25 AM  Permalink




 
INFO-LINK


Related Sites: DotNetJunkies, SD Expo, SqlJunkies