Glassfish vs Tomcat

By , 31 October 2006

Glassfish vs Tomcat

The stack we're using now to build applications for Sunburnt SEO is so close to being a complete Java EE 5.0 environment that I've been giving some thought to dumping support for the old Servlet 2.4 environment altogether. We're now deploying JPA 1.0, JSF 1.2, EL 1.0, JSTL, Mail and Activation jars which account for over 65% of the download size and are all included in a Java EE 5.0 server.

Then there's the other advantages of Java EE 5.0 like dependency injection, transaction management and hooks for automatic Entity enhancement. Needless to say, I'd be quite happy to upgrade.

Well, what better way to decide about an upgrade than to build a comparison matrix? Lets have a look then - a comparison to Tomcat is all I'm really interested in here, although one of the key features of our software is its multisites capability, so support for virtual hosting is especially important.

Glassfish vs Tomcat
Pri Standard features Tomcat Glassfish Comment
1 Adoption levels high low Glassfish is new
2 Scalable ok yes Glassfish has grizzly
3 Includes Java EE 5 jars no yes  
3 Dependency injection no yes  
3 Container managed transactions no yes  
3 OpenJPA entities enhanced automatically no yes  
4 JDBC authentication yes yes In Glassfish 1.0.1
  Virtual server features      
1 Support for virtual hosting yes yes  
1 Deploy same webapp to multiple hosts yes yes  
1 Configure same webapp differently yes no Possible in Tomcat's context.xml or server.xml
2 Per virtual host logging ok yes Tomcat's JULI is a bit buggy [1], [2]
2 Each host has their own authentication realm yes no  
3 Each host has their own deployment dir yes no  
4 Each host has a jailed manager yes no  
4 Each host can listen on a different port ok yes Tomcat requires an additional <Service> containers [3]
5 Each host can listen on an arbitrary combination of ports no yes For Tomcat, a host in one <Service> cannot share ports with a host in another <Service> [4]

The main problem with Glassfish is that its virtual hosting features don't meet our requirements. In Glassfish, webapps don't live in a single virtual host, they are mapped to one or more virtual hosts. This is why you can't have a single deployment directory or jailed manager per virtual host. Additionally, it appears that instances of webapps in Glassfish can't be individually configured by setting environment variables in the config file (the <web-app> section is practically empty) and they cannot be mapped to the same context path even if they are deployed to different hosts.

Glassfish looks great, but the problems above are show stopper for us, so we have to stay with Tomcat unless I come up with a way to do these things in Glassfish.

References

[1] http://issues.apache.org/bugzilla/show_bug.cgi?id=39627
[2] http://www.nabble.com/readConfiguration%28%29-broken-in-juli-t1755780.html
[3] http://www.nabble.com/forum/ViewPost.jtp?post=7107700&framed=y
[4] http://www.nabble.com/forum/ViewPost.jtp?post=7118636&framed=y

Update 2012

Five and half years later and Tomcat is still our server of choice. After trying to upgrade several times to Glassfish we just keep hitting stopper bugs that make me wonder if anybody actually uses it for anything more than "Hello World" applications.

Tomcat might be old and boring, but it is fast, stable and doesn't have buggy features.

About Roger Keays

Glassfish vs Tomcat

Roger Keays is an artist, an engineer, and a student of life. He has no fixed address and has left footprints on 40-something different countries around the world. Roger is addicted to surfing. His other interests are music, psychology, languages, the proper use of semicolons, and finding good food.

Leave a Comment

Please visit https://rogerkeays.com/blog/glassfish-vs-tomcat to add your comments.

Comment posted by: Keba TOURE, 12 years ago

Dear sir,

We need hoster for our JAVA Jee Application, Could you please provide us all informations about it.

Regards

Comment posted by: Stijn, 14 years ago

 I actually liked this comparison table here, thank you.

For all the nay-sayers saying you are comparing apples with oranges... so what? I actually have about the same requirements as the OP and if you need either a lightweight EE container or a bulky servlet container, this is actually a very valid comparison to make. What do I care if Sun calls the thing an EE container or not? I just want a reliable, well configurable system that starts fast and can be used in production. 

Comment posted by: Tim Anderson, 14 years ago

This is actually a pretty good analysis of Tomcat vs Glassfish, although I'm not sure I agree with the Configure Same WebApp differently field. I've been looking for a tomcat eclipse resource, but the best I could find is the one I just linked too, which isn't all too great. Let me know if you have any or are interested in posting one. Thanks!

Comment posted by: Sam Cyrus, 16 years ago

Is it possible to (on the same machine) use Glassfish-frontend-JWS for JEE purposes and Apache HTTP server + Tomcat for usual use like servlet/JSP?

Comment posted by: mecatroid, 16 years ago

Would be interesting to ass a column for Geronimo (I mean Geronimo bundle with Tomcat, not jetty).

Comment posted by: Nate, 16 years ago

If Tomcat is the only thing that Glassfish can win against in a comparison chart, then I wouldn't post one.

Comment posted by: davidecr, 16 years ago

another point or comparison,

J2EE enviroment | Tomcat = no | Glassfish = yes

 

:)

Comment posted by: nhm tanveer hossain khan (hasan), 16 years ago

it seems like, i don't need to move on glassfish. i can't see it is so appealing.

Comment posted by: Dario Laverde, 16 years ago

You can add the OpenEJB 3 container to Tomcat. (http://openejb.org) and change 4 of those "no"s.

I've posted a how-to at http://javanotebook.com

Comment posted by: GlassCat, 16 years ago

So your using C3P0 and the first thing that comes to mind is, "may the force be with you"! Seriously, aside from connection pooling, statement pooling, data persistence, object caching, data relations, data mapping or database abstraction and other Java EE5 aspects, have bearing on the comparison of an E.J.B server (Glassfish), with the open source servlet / web container Tomcat? Pardon my duh but either I've missed the point or we got so left field, we might just compare peanuts with cashews, resolve these last two statements as nuts... and move to WebLogic? Geronimo and Tomcat are separate trunks of Apache.

If you need a Java EE5 Application Server and like the idea of integration with Tomcat, take a look at Grizzly and Groovy, along with of a host of binding components and service engines available to interact with since Glassfish v2. Tomcat (prior to v6) is not a Java 2 Enterprise Edition application server, since its streamlined for JSP / Servlets. The result is being able to handle a greater number of connections due to many of the other advantages that are offered by GlassFish being absent or only partially implemented.

Comment posted by: Andre, 16 years ago

You can use DBCP if you want, I use C3P0 for my connection pool needs and it worked.

Comment posted by: Manuel, 17 years ago
It seems that some people misunderstood what Roger wanted to explain with this table. As I understood, his application needs a servlet-container ( Tomcat in this case ) and additionally JPA, JSF, JSTL, etc. Then, instead of include this modules in addition to the application itself, he asked himself if would be better to use a Java EE server ( GlassFish ), which already includes the servlet-container plus all of the additions required. But, this Java EE server should equal some functionalities found in the servlet-container alone. That´s why just some features are compared.That´s all.
Comment posted by: Jamy, 17 years ago
What perfect said, is that Tomcat and Jetty are Application Server (JSP/Servlet container) whereas GlassFish is an Object Seveur (or EJB container). It's not the same thing.
Usally you use an Object Server with an Application Server.
You an use Tomcat with GlassFish, but better with Geronimo (Apache Fundation) or JBoss (Red Hat) or JOnAS (Red Hat).
Comment posted by: , 17 years ago
Thanks for the feedback. Please understand though, that this is a fairly narrow comparison against a specific set of requirements. It's basically a dump of my decision-making table to answer the question "Do I use tomcat or glassfish for this job?". I did actually look into Jetty, although it didn't hold my interest long enough to make it into the table. No doubt I'll revisit that one day though.
Comment posted by: perfect, 17 years ago
yet another idiotic comparison -- why don't you compare tomcat against jetty
Comment posted by: Ploni, 17 years ago
You are comparing apples to orages:
Tomcat is a servlet-container while GlassFish contains an EJB-Container
Comment posted by: , 17 years ago
Jason Lee has posted a living version of this table on the Glassfish Wiki. I won't be making any updates to this one, but you can log into the glassfish wiki if you want to add your 2c.
Comment posted by: , 17 years ago
Looks like the "Each host has their own authentication realm" feature is now in glassfish: https://glassfish.dev.java.net/issues/show_bug.cgi?id=1537
Comment posted by: , 17 years ago
I've added some of the Glassfish features pointed out by Jan Luehe on the glassfish-users list.