One of our developers has a servlet which calls an RPG program. Under development, the program goes into an infinite loop if accessed with invalid input. This is being fixed. In the meantime, it points out to me the fact that Tomcat will hang if it tries to serve a "bad" servlet. Is there anything I can configure in Tomcat to avoid this situation in the future? It also seems to me (we are new to tomcat and webdevelopment in general) that Tomcat hangs if too many of us (6 of us) are all testing our newly developed database accessing servlets at the same time. Currently, I have to stop and restart Tomcat fairly frequently to un-hang it. This seems to me that I have something configured incorrectly - or something not configured which needs to be configured. I'm using Tomcat 4.1.17 in standalone mode.
What exactly do you mean by "hang" - does it stop serving valid requests or just slow way down? Tomcat can recover from exceptions in servlets but servlets that put the request-response thread in an infinite loop might act "hung." I like to create a new Thread to conduct some time consuming process and give it a lower priority. You can then have the request thread join that working Thread with a timeout so you can recover control if the working thread gets stuck. This is especially useful if you are trying to exec() some time consuming process. Bill Bill
When I say that tomcat hangs, I mean that no output is reflected to the browsers. Browser windows blank out with no error messages or anything. They're just there, empty. I don't understand this part of your response: "I like to create a new Thread to conduct some time consuming process and give it a lower priority. You can then have the request thread join that working Thread with a timeout so you can recover control if the working thread gets stuck. This is especially useful if you are trying to exec() some time consuming process." I don't know how to create a thread, I don't know how to give it any priority, and I don't know how to join a working thread with a timeout. I am just learning Java, Tomcat, and web-development all at the same time. None of my coworkers have any experience either. I hate being so new. I appreciate your help. Thanks,
Wow, you are jumping right into the middle of things aren't you!! You better start by simplifying - create a stand alone program that creates a Thread and performs the RPC call, faking the servlet input, so you can check that independently from the servlet environment. There are so many things that can go wrong with servlets that it is hard to debug in that environment. As far as programming with Threads, any good Java book will have one or more chapters on the subject. If you are on a tight budget, Bruce Eckel's Thinking In Java can be downloaded for free. Bill
Thanks for the help. I'll be downloading that book. I appreciate your time. Still, I'm concerned about Tomcat being so vulnerable. Shouldn't Tomcat be stable in spite of poor programming? I'm still hoping I can do something to help Tomcat run effectively while we are all learning. Thanks again. Robyne
There is no environment so stable that it can't be brought down by bad programming. Just entering an infinite loop in every request will do it to Tomcat. Programming for a multi-threaded environment is not simple, but Java provides a great tool set. In my opinion, the most important thing for you is to approach the problem in step-wise fashion, making sure that the bits work before putting them together in the servlet environment. On the servlet end, use mockups of your complex processes to experiment with presentation. Bill
Bill, Thankyou so much. You've been so kind to keep responding. It makes sense that nothing will stand in the face of poor programming. I should have thought of that. It's just that I've spoken to some people who seldom have a problem with Tomcat and seldom need to restart it. I can't believe we're the only ones who struggle so much. Now, re-visiting the other problem: When there are 5 of us trying to develop servlets and hitting Tomcat frequently, it may also hang. I can't find anything in the logs to hint at what the problem might be. Is it possible that my JVM is too small? I'm running Tomcat 4.1.17 standalone on an IBM iSeries(AS400). I wonder how I can check the size of the JVM. I could probably ask our system manager but he is fairly busy and as new to this technology as the rest of us and I try not to bother him if I can find things out for myself. I hope you have a good day. I love my work. thanks, rob
You might be experiencing what others dread in a "shared host" environment. One person's small little bug turns into everyone's problem. It's quite possible that something else beyond your RPG stuff (or even possibly that) is causing the server to 'hang'.
5-6 developers is not unexpected load on a Tomcat instance.
Are you doing any logging within your code ? If you're looking for "quick and dirty" just use the Servlet's log() method. It all depends on your classes though, sometimes you won't have that method "in scope". I use the log4j package (which can be a bit daunting to set up at first, but it's a joy to use after that) and love it.
The most simplistic logging I can think of is something like So if in your logs you ever see a "entering" without that "exiting", you might have discovered your infinite loop or blocked i/o or hung database connection or... etc, etc.
Also, if this is new to you and everyone, I'm assuming that means you have no current installed base of java web-based applications? If so, and there are no other considerations, is there a reason you're not using the most recent stable release of Tomcat ? It's now at 4.1.24
Hi Mike, Thanks for your suggestions and code. I need that kind of help. I guess I'll try the log4j. I'm somewhat overwhelmed just trying to learn java, tomcat, servlets, jsps, and I'm even new to AS400! It's a long story how I got into this situation, however, I love being in it. I'm enjoying the learning process and the excitement about doing new stuff. Unfortunately, I downloaded 4.1.17 on one of the 2 days when it was available. Immediately, a security flaw was discovered and fixed in 4.1.18. That was not a big concern to me at the moment, as we are behind a firewall and don't plan to go public for a while. By the time we go public, I plan to have a more current version. We have very few applications up and running. However, as new as everything is to us, I feared trying to install a new version without feeling like I knew more. At least this version is working on some level. I had some trouble getting the startup.sh and shutdown.sh to work on our AS400, and that was by following the suggestions of 2 web articles on the subject - neither of which was complete. I occassionally look for new articles on the subject. I fear that the shell scripts may need to change again with a newer version of Tomcat. I had to edit these shell scripts and I've never done scripting languages before. So, I guess the short answer is that I'm scared. I'm afraid that if I download a new version, I'll have to fix the shell scripts and won't get it right for a few days. And that may mean nobody will be able to do anything until I get it right. However, now that I think about it, I guess I could add the new version and get it up and running without bringing the old version down. Well, thanks again. I really appreciate your help. I'll try that quick and dirty logging suggestion first. with appreciation, Rob
Is there some particular reason all of your developers have to use one tomcat installation? It doesn't take that much room and can run on the same system (Windows/Mac/Linux) that you use for editing and compiling. Tomcat 4.1.24 is working fine for me. Bill
Bill, Is there some reason why I would prefer supporting 5 versions/installations of Tomcat? Simplicity is key. If it is going to take 5 installations of Tomcat to support 5 developers, then I think I'd prefer to use Websphere. We all need to hit the same IP address as we are using a code generating tool to help us with some of our development. I suspect that would be the main reason we only need one installation of Tomcat. If I sound like I don't know what I'm talking about - it's because I don't. We do our editing and compiling on the AS400 which is where Tomcat is installed. I have confidence in the newer versions of Tomcat, I don't have confidence in my ability to implement them. Thankyou, Robyne
I have a similar problem and when that happens I try the /sbin/tomcat4 stop/start routine. It restarts tomcat but the other(previous) instance is still left hanging. I have to manually kill the original process to get the system to some sanity?? And its not just an infinite loop that does it, but any servlet that throws an Exception (or hangs for some reason). Tomcat doesn't timeout
Hi Heath, I also have to manually kill off Tomcat when it hangs. And, you're right: it's not just infinite loops that will hang it. What's hard is telling what hangs it. Anyway, I'm going to try that logger and see if I can see what's happening. Good luck to us. rob
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop