2 Replies Latest reply on Oct 3, 2003 9:40 AM by cstettler

    Class Reuse and Classloader Issue

    cstettler

      Hi there,

      I just wrote two small EAs,e ach in its own .ear file as specified. The setup is the following:

      EA A:
      - a-ejb.jar with BeanA
      - CommonClass.class
      - descriptors

      EA B:
      - b-ejb.jar with BeanB
      - CommonClass.class
      - descriptors

      Both x-ejb.jars contain one distinct Session Bean with one method, calling a method of CommonClass.

      Deployment works fine, but when calling each Session Bean from a simple client, BeanA gets loaded from Classloader #1, BeanB from Classloader #2, and - suprisingly - CommonClass from Classloader #1, too, no matter which Session Bean called the CommonClass method.

      This means, that te two EAR share the same instance of the CommonClass, which may lead to problems if CommonClass exists in two different version or - even worst - one CommonClass has nothing to do with the other CommonClass except of the same name and package.

      I would expect all classes from one EAR to be loaded by a single classloader that is not reused for any other EARs. Otherwise, using static fields would be impossible, not only not in EJBs (as specified by J2EE), but also in all helper classes and other third party libraries.

      May anyone comment on this?