users@glassfish.java.net

Re: Glassfish2.1 clustering, servlet context, and servlet init

From: Jan Luehe <Jan.Luehe_at_Sun.COM>
Date: Thu, 30 Apr 2009 12:06:20 -0700

On 04/30/09 10:32 AM, glassfish_at_javadesktop.org wrote:
> really??
>
> Doesn't this make ServletContext usless then ina clustered environment?
>
> I would have assumed state replication was a defacto part of the GF clustering. Without it, clustering is going to fail for any app that counts on that state to coordinate users.
>

A primary purpose for ServletContext attributes is to store an
in-memory cache of *read-only* data that is repeatedly used and shared
across all users of the application. Typically, a ServletContext is
populated
from a database, or from properties files, or some other source,
either at application startup, or lazily the first time the data is
requested.

Any non-read-only-, i.e., mutable-shared-data needs to be stored in a
Session.
A Session may migrate between cluster instances, but will never be accessed
on two cluster instances at the same time.

This is further explained in Section 4.5.1 ("Context Attributes
in a Distributed Container") of the Servlet spec:

  Context attributes are local to the JVM in which they were
  created. This prevents ServletContext attributes from being a shared
  memory store in a distributed container. When information needs to be
  shared between servlets running in a distributed environment, the
  information should be placed into a session (See Chapter 7,
  "Sessions"), stored in a database, or set in an Enterprise JavaBeans
  component.


Jan


> [Message sent by forum member 'jeffpk' (jeffpk)]
>
> http://forums.java.net/jive/thread.jspa?messageID=344536
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>