You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Achim Hügen <hu...@entrice.de> on 2003/03/07 13:39:48 UTC

Use of threads causes LinkageError in WebappClassLoader

I have some problems with LinkageErrors with tomcat 4.1.18, that resemble 
those described here:

http://archives.apache.org/eyebrowse/ReadMsg?listName=tomcat-dev@jakarta.apache.org&msgId=202486

My Web-Application starts some jobs in threads. Starting only one job at a 
time doesn't make any problem.
When I start multiple jobs, sometimes the whole application locks up and 
sometimes I get
LinkageErrors due to duplicate class definitions. The behaviour is rather 
nondeterministic and
changes when inserting random pieces of code.
All the jobs use some libraries which have not been loaded before the 
start of the threads.
So I assume that there is (still) a race condition or deadlock in the 
WebappClassLoader.

The nature of the problem makes it difficult to provide a test case.

I took a look in the source. One thing that caught my eye is a double 
checked locking in
method findClassInternal:

        if (entry.loadedClass == null) {
            synchronized (this) {
                if (entry.loadedClass == null) {
                    clazz = defineClass(name, entry.binaryContent, 0,
                                        entry.binaryContent.length, 
                                        codeSource);
                    entry.loadedClass = clazz;
                } else {
                    clazz = entry.loadedClass;
                }
            }
        } else {
            clazz = entry.loadedClass;
        }

The problems of the double checked locking idiom are well known.
Maybe this is the reason?

Achim