How Tomcat Works 171
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.
Judge (Score:5, Funny)
But I thought we weren't supposed to judge the book by it's cover?
Re:Judge (Score:1, Insightful)
Re:Judge (Score:2)
Re:Judge (Score:1)
Really, if you're going to be (even humorously) pedantic, you might take more care to be correct.
Re:Judge (Score:2)
Re:Judge (Score:3, Insightful)
Is this a person who spends a lot of time reading technical books?
recently a friend of mine published a book. a pretty serious technical book and by my estimation one of the better books I have seen on the topic.
the problem is that if I saw this book in the store, I would probably just give it a cursory glance and never even bother to take it off the shelf to leaf throu
It is true, but why not? (Score:2)
For instance, I judge cereals by the cover, a whole new box. Now bearing in mind a box of cereals fills that quasi-intimate moment where I am still half awake, and I lovingly spoon it into my mou... oh, sorry.
You see, books have to be appealing to us, technical books have to say, read my witty and easy going words, and you will be amused and infused!
In a semi-related issue. In the new world of e-publishing, we see the internet is
Re:Judge (Score:2)
Sounds like a nice book... (Score:1)
Re:Sounds like a nice book... (Score:2)
Our local school system here is blackboard [ebayimg.com] too. It's proven technology and it really works well. The licensing fee is really low too!
Re:Sounds like a nice book... (Score:1)
You can't change the TC settings with Blackboard (Score:2)
Re:Sounds like a nice book... (Score:1)
Session issues call for something like Coherence [tangosol.com] for clustering, letting you scale horizontally by running any number of Tomcat servers.
Re:Sounds like a nice book... (Score:1)
Seems quite basic.. (Score:1)
A Microsoft Defender Speaks Out (Score:4, Interesting)
Re:A Microsoft Defender Speaks Out (Score:2)
Sadly, I'm out of coding now, but it was fun. I'm suprised to hear an MS guy going to Java/Tomcat (I assume Linux as well), most of the MS-guys I know are pretty hardcore. What's the driver here?
Re:A Microsoft Defender Speaks Out (Score:2)
Re:A Microsoft Defender Speaks Out (Score:1)
OUCH!
Apparently Generalizations in SlashDot = Flames from Readers
Of course not EVERY application. Web applications are my forte, so I was speaking mainly toward Tomcat and JSP. Of course, I recognize the performance issues of large solutions in Java. Tomcat has done well to minimize the overhead of Java somehow. Perhaps because web applications usually have such a small footprint themselves. Maybe the book will tell us such things..
Re:A Microsoft Defender Speaks Out (Score:5, Interesting)
I happen to agree with the GP. If I started my own company, I would use Java/JSP. It would give MY company the most choice on what platform(s) to run. If I wanted to run all MS Windows. Fine. Java runs great under MS Windows servers. If I wanted Linux or Solaris, it is great as well since Java run great there too.
Re:A Microsoft Defender Speaks Out (Score:1)
I suppose one opinion deserves another. No baiting here. But, I suppose if I were to bait my comments, I'd catch you again.
Thanks for the input. I have to be honest when I say that you are the 1st person to tell me their Java app runs quickly. Most people I know (perhaps because I work with MS people) think it is slow as well and I believe the majority of programmers think the same. Perhaps a poll?
Anyone know how to steer this boat back on topic? I suppose we'd better abandon
Re:A Microsoft Defender Speaks Out (Score:3, Insightful)
Umm, maybe because you have no experience with real Java? I can run .Net apps that are very bad and very slow. Does that mean I should think .Net sucks?
I think you have your answer there. .Net is not any more faster or more efficient than Java. I work for a fortune 500 with 140,000 employees. I have met plenty of people like you that don't really understand
help wanted (Score:1, Offtopic)
How does it compare to OReillys book? (Score:5, Informative)
About the only thing common between an Applet and a Servlet is that both are writen in Java. Anyone out in
Re:How does it compare to OReillys book? (Score:3, Informative)
Re:How does it compare to OReillys book? (Score:3, Informative)
Re:How does it compare to OReillys book? (Score:3, Interesting)
Some of the sites on the windows box go down once a day or more, but again that's probably a configuration thing. I've never had any problems developing on either.
IMHO Tomcat has come a long way in the last few years.
Re:How does it compare to OReillys book? (Score:1)
Re:How does it compare to OReillys book? (Score:2, Interesting)
The sites are high-traffic (many hundreds of user sessions per day). "Hundreds" probably doesn't sound like much, but the apps are pretty intense...not just simple SQL query/display stuff. High-end graphics manipulation, workflow management, and more, with sessions lasting 10-20 minutes each.
The base OS on every server is Red Hat. Rarely do we experience problems, and in 99% of the cases, the problems are user-
Re:How does it compare to OReillys book? (Score:1)
Re:How does it compare to OReillys book? (Score:1)
We'll be using it (Score:2)
Would have been nice (Score:5, Informative)
Re:Would have been nice (Score:5, Insightful)
You say its poorly implemented but yet say you dont know how its works or much about Java. How can you possibly judge the quality of implementation?
Tomcat is a mature and established technology. There are a plethora of 'getting started with tomcat', 'setting up tomcat' and 'integrating tomcat with your favourite ide' articles available on the web, before even consulting Amazon.
It is a doddle to install, setting up a site on it takes a bit more time. As with almost all software the documentation could be better but its not like there is not other info available.
Re:Would have been nice (Score:1)
Having used Tomcat as an SA and now Java developer I can relate to the parent post.
When I first had to admin Tomcat deployments I found configuring environments very odd. Now that I have to package our products for other SAs I have the feeling that they won't stand much of a chance in changing any live configuration without our guidance. The point is that they should not have to know much about Java to be able to find the correct configuration information.
Our SAs weren't familiar with Apache httpd eithe
Re:Would have been nice (Score:1)
I'm going to go try again right now, I'll let you know how it goes...
BTW, Tomcat != J2EE
Use the jk and not the jk2 connector (Score:2)
There are some additional steps including permission setting to get IIS to use the redirector.
More info here: http://www.rit.edu/~ack5504/tomcat-iis6-howto/tom
Re:Would have been nice (Score:2)
Re:Would have been nice (Score:1)
Re:Would have been nice (Score:2)
And its not just a matter of doing what you said. The client wanted Fedora Core 3 installed, which lacks Java stuff and so compiling Ant alone because problematic. In the end I wound up convincing them to let me install Fedora Core 2, which comes with all those packages.
Re:Would have been nice (Score:1)
Re:Would have been nice (Score:2)
Opinions Vary (Score:1)
struts? (Score:3, Insightful)
Ishmael
what as bad as writing them? (Score:2)
you then go through the whole login thing only to find out you screwed the configuration file.
java/html/struts single handedly killed my love of coding within a year. coded since i was 11, now 33. hardly touch code now even for f
Re:what as bad as writing them? (Score:1, Insightful)
Re:what as bad as writing them? (Score:2)
java is still overkill for working with web pages though.
oh and the run everything through apache - sounds a bit like early novell
Re:struts? (Score:1)
And be sure to put a whoring link to book, so you can make tons of cash on Slashbots who click the link and buy it.
Re:struts? (Score:1)
Object instantiation is cheap! (Score:5, Informative)
From this follows that object pools are counterproductive for performance (unless, of course, if resources are associated with them, like Database connections, open sockets, etc.).
I heard that quite a few app servers (including JBoss) started to refactor to get rid of object pools, but I don't have a link to back this up.
Re:Object instantiation is cheap! (Score:3, Informative)
Re:Object instantiation is cheap! (Score:3, Informative)
Another case of premature optimization hurting (in added complexity and potential bugs) more than it helps?
maybe it's just bloated? (Score:3, Funny)
If that's true, it sounds like it is bloated and not very well designed.
Re:maybe it's just bloated? (Score:3, Interesting)
Oh, and also - all this reminds of when I herd ESR say in a talk that the markets cry for java was really a cry for FOSS. While I've never been a great fan of ESR - I think maybe he was right. The whole idea of java was to move the development center of gravity away from the proprietary desktop. Heck f
Re:maybe it's just bloated? (Score:3, Insightful)
It's ironic, though, that Java is anything but FOSS...
ANd, also I think it was a mistake to force the java solution to be a high level language.
I don't think that was necessarily bad. What was bad that they completely forgot about their original mission: lightweight clients. A decade later, we have another bloated server-side platform we don't need (Java), and we still don't have
What about for admins? (Score:2)
I'm not a java developer, I don't want to be a Java developer, but I have users who do.
All of the Tomcat docs I've seen are written from the developer perspective. I need to be able to set up and maintain a development environment for students where they can work, and that doesn't crash the tomcat server every time somebody makes a coding error. But I have no desire to learn Java, only enough Tomcat to keep it running.
Sample Chapters (Score:4, Informative)
Strongly Disagree with Review: Not a Good Book! (Score:5, Informative)
"How Tomcat Works" is a potentially good idea, done badly.
The writing is awful. Not just inelegant, but frequently so bad that it gets in the way of the ideas being presented. Spelling, typos, grammar problems, convoluted sentences, miswordings that invert the meaning of a sentence entirely: this book has all that, and more. A fourth grade teacher with a red pen would have made this a much better book.
A book on "Tomcat Internals" is a wonderful idea; Tomcat's a somewhat complicated beast. But the approach that this book takes... it just didn't work for me. It's possible that I simply couldn't get past the bad writing. Or it may simply be that it doesn't meet my needs. I'm familiar enough with Tomcat that I don't need it explained in tiny little baby steps. What I do need, when I'm up to my ankles in Tomcat internals and trying to solve a particular problem and get on with my life, is a clean, well organized book that will quickly get me oriented, refresh my memory on the relevant bits of Tomcat's architecture, and point me to the solution to my problem. This book fails to do that.
The production values in this book leave a lot to be desired. There aren't enough diagrams, and, at least in my edition, the few that do appear are printed at very low resolution. The index is a joke. (Hint for the authors: a quick indexing script doesn't always make a useful index, okay? Second hint: hyphens denoting sequential pages are cool.)
I've learned a lot about Tomcat since reading this book... mostly by wading through the source code. After a quick initial read-through, "How Tomcat Works" has stayed on my bookshelf, untouched, for at least five or six months. This book will join "Apache Server Commentary" in the pile of books that seemed like a really good idea, but in the end, were much less helpful than I had hoped.
If you just need a book on installing or using Tomcat, or writing Java servlets in general, there are many better books. If you need a book on Tomcat internals, you probably need a better book than this one.
Re:I could be off base, but... (Score:1)
I'll bet this is a troll. No specific details, could do a s/Tomcat/whatever/ and get the same review, the classic calling cards of a book review troll. You make the call...
Sorry, not a troll. Download part of the book and judge for yourself:
You might like this book. I did not.
With better prose and better production values, a second edition might be worth a second look.
Re:I could be off base, but... (Score:2)
I tend to be pretty skeptical of technical books from anyone other than O'Reilly, Addison-Wesley, or Prentice-Hall.
Re: (Score:1)
Tomcat is NOT a J2EE server (Score:5, Informative)
As a J2EE programmer, I find the reviewer's statement to be a bit misleading.
Tomcat is not a J2EE server. The J2EE specification deals with Web Components (Servlets, JSPs) and EJBs (various EJB types and related services). Tomcat only satisfies part of the the full J2EE specification by serving Servlets and JSPs. Therefore, Tomcat is only a Web Container.
JBoss [jboss.org] is an example of a J2EE compliant app server.
Tomcat versus others (Score:2)
I have used many other java application servers and they don't really come close. WebLogic dev environment and stability made me appreciate a root canal. WebSphere taught me patience while waiting for the debugger to start (if it doesn't crash while starting); not to mention the debugger can easily use up 1GB of ram while running. iPlanet, well I
Re:I feel stupid but... (Score:5, Funny)
Re:I feel stupid but... (Score:1, Informative)
Re:I feel stupid but... (Score:2)
Gah. This brings backs bad memories. I was at a company a couple of years ago and was going to download Tomcat. So I took my browser to www.tomcat.com, with lots of other people in the room. Guess what! Porno domain. I try to close it the browser. New popunders come up as quickly as I try to close them (it was the company computer and they used IE, ok?). At any second someone could
Re:I feel stupid but... (Score:5, Informative)
It can run standalone and also serve static files such as HTML pages/graphics, etc., or it can be configured to stand behind a web server such as Apache and only handle the servlet and JSP requests that are passed to it.
Tomcat is itself written in Java and is, of course
Re:I feel stupid but... (Score:3, Insightful)
Ehrm, technically, yes. But I'll be damned if I could get the thing to be stable when I tried to set it up.
See, at my (brand spanking new) dorm, we needed a homepage. So this dude volunteers to make one, and is sent off with the words "It must work on a standard Linux/*BSD platform. No proprietary crap, please." A week later, he shows us this impressive thing runn
Re:I feel stupid but... (Score:2)
My guess is, based on crashing and slowness remarks, that whomever coded the app you're using sucks.
It's like blaming PHP/Perl/c++ for a shitty program that happens to be written in said language.
Does the fact that phpnuke has tons of security vulnerabilities and is slow as hell mean php sucks?
better experience with Jetty (Score:2)
Re:I feel stupid but... (Score:2)
Re:I feel stupid but... (Score:1)
Re:Could the editors... (Score:1, Informative)
It lets you deploy your Java Servlets and JSP pages, among other things.
Re:Could the editors... (Score:2)
Tomcat is many things:
The key is understanding what a servlet is. A servlet is an instance of a Java class that is invoked in response to an HTTP request. In other words, it's custom Java code for handling and responding to HTTP request by web browsers and other clients. Th
Re:And those are? (Score:3, Informative)
If you're a student, particularly in a technical field, you should be able to google something and learn what it is. As you progress in your technical career, you'll spend a lot of time looking up technology and solutions. It's the nature of a fluid field.
My EE profs had no patience with students who wouldn't do their own research and I've been the beneficiary of that attitude.
Learning a topic is something that should be obvious. If you are to be c
lazy students (Score:5, Funny)
Re:lazy students (Score:1)
Re:lazy students (Score:1)
This guy was about as informative as the web site. [slashdot.org]
This one agreed with me. [slashdot.org]
Let the flames begin! (Wait, too late for that. Must be a bad karma day.)
Re:lazy students (Score:2)
Re:Could the editors... (Score:2)
Servlets are Java programs that handle specific events (such as requests to a URL) and Tomcat is an apache plugin that lets you run servlets from apache.
New web cartoon: Jendini.com [jendini.com]
Re:Could the editors... (Score:3, Informative)
Re:Is it just me (Score:5, Insightful)
Look, I used to hate Java, and quite frankly I can't say I love it much yet. But to be honest, it's come a long way since the days it was unbearable. So please come off the Java bashing, it's passé. Either that or upgrade your system for crying out loud...
Re:Is it just me (Score:3, Funny)
Well, Tomcat itself is an application... written in Java... often abbreviated as a "Java App". Deploy a couple of webapps in tomcat and then check out the memory footprint of Java.exe and you'll see what he means. I've never used tomcat for production use although i do have 5.0.28 running on my workstation to test stuff, and i'v
Re:Is it just me (Score:1)
Re:Is it just me (Score:5, Informative)
Re:Is it just me (Score:5, Interesting)
I keep getting flamed by the moderators but do a search on the CIA's website for insecure langauges and software.
Php is the least secure langauge in existance and has more holes than even ASP.
I do not mean to sound trollish but its the truth and the next big wave of worms will probably be targetting at websites running php.
Re:Is it just me (Score:1)
it's not languages that are insecure; no matter what language you use, you need to have competent programmers.
Php is safe and robust, simple and elegant. You can build small or big applications. It is technically *simple*, and that means you don't need books like the one we're discussing here. Just learn the language and you're all set.
Now take an incompetent programmer, and they will build you an insecure system, no matter what language you use.
Re:Is it just me (Score:2)
Well, you're right that you *do* need competent programmers to build a secure system, no matter what language you are using. You're wrong on your first point, though. PHP and Java both run in interpreters -- that's software which *itself* can have exploitable flaws.
Language design also does make a difference in security. Even if all interpreters and runtimes were perfectly secure (they're not,
Re:Is it just me (Score:2)
That's
Re:Is it just me (Score:1, Informative)
PHP NOT (Score:1)
Re:Is it just me (Score:2)
You have just described a weakly typed language.
Re:Is it just me (Score:2)
That's not the question. The question was:
Which is what I (and others) answered. It called for no value judgement.
Re:Is it just me (Score:2)
with that said, php/apache is truly a joy and is my preferred web-deployment platform. java is my preferred platform for regular old applications.
Re:Is it just me (Score:3, Insightful)
I think of it this way... PHP for web applications is inevitably like building your own house from scratch... mixing the concrete, cutting down the trees, etc. All by yourself. As I've developed some web applications in PHP, this is acceptable if you're building a yurt or something.
Java servlets are what you want to use if you want to ensure some level of expandability, or at least standardized
FrontPage (Score:1)
Re:A new copy is not available from Barnes & N (Score:4, Informative)
And maybe someone just wants to make money on their amazon referral?
It is available from BN for $10 less.
Re:Oh, Java (Score:2)
Re:I don't want to start a holy war (Score:2, Informative)
And there is no reason at all to mix business logic & content - in fact, application frameworks like Struts make it *hard* to do so.
The rest - slowness, memory use, etc. - could apply to any commonly used platform. I've seen studies that put c
Re:I don't want to start a holy war (Score:2)