Slashdot Mirror


How Tomcat Works

Petri Aerikkala writes "Don't judge a book by its cover, but by what it covers. How Tomcat Works has a very ordinary cover, but I cannot overemphasize how useful its contents are. This book does what the title says, plus much more. It is useful for not only those using Tomcat or those working with servlets/JSP/J2EE, but also for all Java developers in general." Read on for the rest of Aerikkala's review. How Tomcat Works author Budi Kurniawan and Paul Deck pages 458 publisher BrainySoftware rating 8 reviewer Petri ISBN 097521280X summary Explains how Tomcat works and how to build a servlet container of your own

First of all, this is the only book I know of that explains how the complete system works. You can find good documentation on how to use this most popular servlet container on the Tomcat project's Web site, but little is said about how it works. If you want to join this open source project, good luck. You should consider yourself lucky (or very brilliant) if you can understand how the system works in less than 3 months by browsing through its millions of lines of code.

However, why I find this book appealing is because of the approach the authors take in analyzing it: build Tomcat from scratch, line of code by line of code, module by module. Miraculously, in doing so they never fail to make sure their readers can follow the technical discussions. In their hands, Tomcat looks easy that even beginners of Java can understand. There are many complex technologies used in Tomcat, and they are all explained well.

The book starts off by building a dummy Web server that can do no more than sending a static HTML page. The web server is simple and consists of only three classes. The backbone of this application is the java.net.Socket class, and the authors take their time explaining this class at the beginning of the chapter. Basically, this is how the application in this chapter works: for each HTTP request, open a socket connection to the client, read the content of the static file, and send the file to the browser. As simple as that.

Chapter 2 builds on the application in Chapter 1. In this chapter, the web server gets some intelligence. It is now able to invoke a basic servlet by calling the servlet's service method. However, more complex servlets are beyond this simple servlet container, mainly because the container passes a null ServletRequest and a null ServletResponse objects to the service method. Before the authors start coding, they explain the javax.servlet package in general so that those new to servlet programming can understand this chapter.

Chapter 3 explains how to create ServletRequest and ServletResponse objects so that the servlet container in Chapter 2 can do more. The excitement comes in Chapter 4 when the authors explain how to pool ServletRequest and ServletResponse objects to beef up performance. This topic is not only relevant to Tomcat, but also Java programming in general. Object instantiation is expensive, and one way to avoid it is by reusing objects. However, you must be careful when your application will be used by many clients, as you must then think about thread safety. Chapter 4 elegantly explains how Tomcat developers solve this problem, as well as teach you a general solution for object pooling. Interestingly, a servlet is always represented by a single instance, and the same instance services all incoming requests.

The authors are also patient in explaining everything step by step, until the last chapters where they tackle more difficult problems such as Digester, JMX, class loaders and session management.

Not only will you be good at configuring Tomcat after you are finished reading this, you will also be able to tell straight away what's going on whenever your Tomcat installation throws up some error message. In addition, if you are really serious about Tomcat, you can start thinking of writing your own modules or extending the existing ones. For example, as the authors have demonstrated, you can extend Tomcat's application loader to automatically reload a Struts application when the struts-config.xml is modified, making the application development process quicker.

This book is also great in answering many questions that seasoned servlet/JSP programmers might have long been pondering. For example, this book discusses the difference between an OutputStream and a PrintWriter, and why you can only use one of them rather than both. It also tells you why you cannot write to the request parameters or headers.

Now, as much as I liked it, this book is not perfect. The first noticeable flaw is that there are quite a number of disturbing spelling mistakes. Also, the index could have been better, not to mention a cover that is plain and uninspiring. However, I have to admit I am very happy with this book and will recommend it to any Java programmer.

You can purchase How Tomcat Works from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

11 of 171 comments (clear)

  1. I feel stupid but... by ilyanep · · Score: 0, Troll

    What's Tomcat?

    --
    ~Ilyanep
    To get message, take amount of carrier pigeons at each stage mod 2. Then decode binary.
    1. Re:I feel stupid but... by Post+It+Now · · Score: -1, Troll

      You must be new...nope, low uid. The only person at slashdot who actually uses linux or firefox is the guy who set up and admins the servers that slashdot runs on. By the way, Slashdot runs on FreeBSD, they just fake the headers in Apache. That guy who admins the servers...he has to install whatever latest video game comes on maldas xp box, because he can hardly be bothered to do that. Aside from mashing their hands on the keyboard and thus outputing more slashcode, the editors do little more than play games and watch anime.

  2. Could the editors... by students · · Score: -1, Troll

    Please do the research for us before posting?
    What is Tomcat? Something used to make Java Servlets?

    From java.Sun.com
    "The Java Servlet specification was created under the Java Community Process to provide full public participation in the definition and development."

    So what does that mean practically speaking?

  3. Is it just me by Prince+Vegeta+SSJ4 · · Score: -1, Troll

    or do java apps take up a huge amount of system resources? Everytime I launch one, my system crawls.

    1. Re:Is it just me by Anonymous Coward · · Score: -1, Troll

      Hmm...
      So one minute you are talking about how much bloat there is today and how your 386 DX Slackware box still loads faster than the latest tech...

      Yet when it comes to Java, everyone is full of excuses- "Upgrade your machine n00b!", "Java isn't as slow if you have the latest test release of Sun Java VM and are running on a cray", "hey, those memory leaks don't bother me!".

    2. Re:Is it just me by Anonymous Coward · · Score: -1, Troll

      Who modded this down as a troll? This is seriously true!

      As an example, I fired up a freshly unzipped copy of Tomcat, and it comes in at 28MB. It can't do anything yet, though, because I haven't installed any webapps. So, next, let's run through all the samples. Now I'm up to 44MB of memory usage! And it still can't do anything useful.

      For a comparison, I've also got an Apache 2.0 server running that has PHP installed and has been running an actual web application for quite some time now. It weighs in at 20MB total - less than the base memory requirement of a Tomcat install!

      Now, I understand that Tomcat is a "web application" server and is designed for using dynamic content. But Apache with PHP does that too - what does Tomcat offer me that PHP does not, other than needless bloat and heavy system requirements?

      About the only answer I've ever gotten is something about "enterprise" related things, but never any example of why this requires Tomcat and can't be done cheaper in Apache using PHP. (And once you say "enterprise," most people seem to agree that you shouldn't be using Tomcat anyway, so - what exactly does Tomcat provide?)

  4. No, Sir, Not going there. Tomcat is SPYWARE by arothstein · · Score: -1, Troll

    I installed it once and my symantec went batshit crazy on all of its DLLs. It reported it as a ton of spyware. EZULA, coolshredder, you name it. WTF is Slashdot thinking????

  5. A new copy is not available from Barnes & Nobl by Anonymous Coward · · Score: -1, Troll

    Get it form Amamzon.com
    How Tomcat Works

  6. And those are? by students · · Score: 0, Troll

    What? If I had a servlet, what would I do with it?

  7. Oh, Java by Euphonious+Coward · · Score: -1, Troll
    I guess this must be something related to Java.

    Not to disagree with the claims in the first paragraph of the article, I can't imagine how this could possibly be useful to me. Maybe he should have said it would be "incredibly useful" for somebody actually doing web-server-side Java.

  8. Re:A Microsoft Defender Speaks Out by Anonymous Coward · · Score: -1, Troll

    if I started a business of my own, all applications would be written in Java/JSP

    Well, with any luck, you will not start a business of your own. If you do, you will likely get crushed by someone else with a similar idea, who decided to implement a version that was fast, efficient, and did not rely on another server to operate properly. Java/JSP have their time and place, but all the time and anyplace is NOT the answer.

    Have you ever used a program of any significant size that was written in Java? Is it done loading yet?