NoClassDefFoundError if you're too keen accessing Tomcat

A

Andy Fish

Hi,

I have spend several hours trying to track down an intermittent problem with
Tomcat 4.1.27. I was getting NoClassDefFoundError and the stack trace
pointed to a class that clearly did exist in the same jar file as the
calling class.

I eventually tracked it down to this: If I start up Tomcat and then try to
load the page while tomcat is starting up, this error sometimes/usually
appears. If I wait until tomcat has quiesced and then load the page, I never
get the error.

I've recently upgraded from 4.1.18 to 4.1.27 and I'm sure the problem wasn't
there before. looks like a race condition in the Tomcat startup code.

Andy
 
A

Andy Fish

OK, I take it back.

Maybe it's more likely to happen if you try and access while tomcat is still
starting, but on the whole it just seems random and I can't fathom out the
reason at all.

anyone else ever seen this type of problem?

just to reiterate the symptoms, the first time I try to access my servlet,
it gets loaded and seems to initialise without problems. in the service()
call, about 20 deep in the stack trace under service(), there is a
NoClassDefFoundError when one of my classes invokes another of my classes
from the same jar file. It happens at the same place every time, which
happens to be inside a JAAS login module but I don't know if this is
significant.

This error happens about 1 in every 2-5 times I start up tomcat. When it
happens, my servlet won't work until I restart tomcat, but other servlets
work fine.

I'm stuck

Andy
 
A

Andy Fish

I finally found the problem. It turned out to be not where I was expecting.
Although the problem is relatively simple to explain, it's only tenuously
related to the symptoms.

Here's the answer anyway, partly incase it helps anyone else with a similar
problem but mostly because I just had to tell someone about it and there's
nobody here that would understand.

When you shut down Tomcat it serialises session objects. when you start it
back up again it tries to deserialize them. It does this during the catalina
initialization before loading your servlet, and it does it even if you have
persistent sessions turned off!!

In the class in question, there was some static initialiser code that relied
on the fact that the servlet had been initialised and so when Tomcat tried
to deserialize the object, the class failed to load. Tomcat just swallowed
the error, but the next access to the class (which just happened to be in a
JAAS login module) generated a NoClassDefFoundError.

If you now restart tomcat again, there are of course no sessions to persist,
so the next startup works OK. The upshot is a flip-flop effect where every
alternate restart causes the error.

The moral of the story is that you can't rely on your servlet's init()
method being called before your classes are loaded.

Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top