(Original question had empty subject line -- see below)

The Question of the Week is definitely for real. Static information should only
be accessible to servlets within a single ClassLoader context. Different
instances of one single servlet class invoked through one name/url (i.e. one
service) are able to use the Singleton pattern to share objects. Instances of
different servlet classes, or of different services (more names), may (and
should) not be because they may (and should) be loaded by a different
ClassLoader.

I am willing to believe that your system does allow this type of sharing, in
particular if the Singleton class is loaded through some system CLASSPATH.
Any 'public static' information modifiable in this way compromises the security
of information in your servlet and may cause unwanted interactions between
servlets if you are unaware of that. It is better to use the method proposed by
Sun because it is safer and portable between servers.

Even better is not assuming that the other servlets of your application will run
in the same servlet support. If I were an ISP or systems administrator, I would
not guarantee that. I would test the servlets in different servlet support
environments and reject them if they turn out to require eachother's presence.

The recent thread "Sharing static variables between servlets" discusses this
type of sharing in the context of a specific servlet support environment. Jud-
ging from the QoW of Sun, Sun does not approve of this type of servlet-specific
code.


Alexander W. F. Boer
Dept. of Computer Science and Law,
University of Amsterdam, the Netherlands
email: [EMAIL PROTECTED]

----- Original Message -----

Van:    Dino Valente[SMTP:[EMAIL PROTECTED]]
Antwoord naar:  A mailing list for discussion about Sun Microsystem's Java             
 Servlet API Technology.
Verzonden:      Wednesday, October 06, 1999 11:40 PM
Aan:    [EMAIL PROTECTED]

Hi all,

Has anyone checked out the question of the week from the Java Developer
Connection ( http://developer.java.sun.com/developer/qow ; How can I share
objects among servlets)?

Is this question for real as well as the answer? In other words, you can't
use the Singleton pattern with servlets? (I don't seem to have this problem
in my system).

dino

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to