Tip: HttpSession replication in a clustered environment.
Session replication is the term that is used when your current service state is being replicated across multiple application instances. Session replication occurs when we replicate the information (ie session attributes) that are stored in your HttpSession. The container propagates the changes only when you call the setAttribute(……) method. So mutating the objects in a session and then by-passing the setAttribute(………..) will not replicate the state change.
Example If you have an ArrayList in the session representing shopping cart objects and if you just call getAttribute() to retrieve the ArrayList and then add or change something without calling the setAttribute(……………) then the container may not know that you have added or changed something in the ArrayList. So the session will not be replicated.
-- By Author of the book "Java/J2EE Job Interview Companion" at http://www.lulu.com/java-success
Best practices: Servlet best practices for scalability
The clustering promotes high availability and scalability. The considerations for servlet clustering are:
--Objects stored in a session should be serializable to support in-memory replication of sessions. Also consider the overhead of serializing very large objects. Test the performance to make sure it is acceptable.
-- Design for idempotence. Failure of a request or impatient users clicking again can result in duplicate requests being submitted. So the Servlets should be able to tolerate duplicate requests.
-- Avoid using instance and static variables in read and write mode because different instances may exist on different JVMs. Any state should be held in an external resource such as a database.
-- Avoid storing values in a ServletContext. A ServletContext is not serializable and also the different instances may exist in different JVMs.
-- Avoid using java.io.* because the files may not exist on all backend machines. Instead use getResourceAsStream().
-- By Author of the book "Java/J2EE Job Interview Companion" at http://www.lulu.com/java-success 50% off until next 200 copies are sold.
By Michael Tzoanos in forum Database
Last Post: 08-09-2002, 02:07 PM
By Paul Moss in forum Database
Last Post: 04-26-2002, 11:40 AM
By Claire in forum Database
Last Post: 02-08-2001, 01:06 AM
By wrench wrench in forum Database
Last Post: 07-04-2000, 06:04 PM
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL