Discussions

General J2EE: Scope of static class (Singleton)

  1. Scope of static class (Singleton) (1 messages)

    Suppose you are running a single application server node, but you install two different ear files (applications).  These two have certain "common code", classes that they both use.  Now suppose that one of these classes implements the Singleton pattern, and is used to control access to (in effect) a piece of  global memory.  Each of the two classes has the same path, in the sense of having the same name and package statement, but in different jar files.

    So where are we going with this?  Are there, in fact, one or two copies of the class being maintained by the JVM?

    Threaded Messages (1)

  2. clarification[ Go to top ]

    So, looking this over, I'm not sure it's clear. The directory structure, then, is like this: deployments App1.ear App1.jar com.this.that.ClassX App2.ear App2.jar com.this.that.ClassX com.this.that.ClassX is static and implements the Singleton pattern.