5.5.2 Application code
Home

IBM



5.5.2 Application code

When coding applications that you plan to use with eXtreme Scale, remember the following guidelines:

All session objects that need to be stored in the grid have to be serializable, that is, they must implement the java.io.Serializable interface.

Set all application objects or data that needs to be recovered in the event of a failover on the HTTP session object. A common mistake that developers make is to forget to save an object to session after an update.

Example 5-11 shows code that retrieves a shoppingCart ArrayList attribute from the session object and updates it. After the update, the shopping cart list is never updated into the session. If a failover occurs in this case, the session gets invalidated out of the session cache and gets reconstituted from the grid under a new session, and the shoppingCart data is lost.

Example 5-11 Bad Code: storing application data in session

ArrayList list = httpSession.getAttribute("shoppingCart");

list.add("item1"); 

Example 5-12 shows the correct way of doing this. After the ArrayList has been updated with an added item, it is placed back in the session object. In essence, any update to an object that is stored in the session should be directly updated in the session so it can be pushed out to the grid.

Example 5-12 Good Code: storing application data in session

ArrayList list = httpSession.getAttribute("shoppingCart");

list.add("item1");

httpSession.setAttribute(list);


Error 404 - Not Found

Error 404 - Not Found

The document you are looking for may have been removed or re-named. Please contact the web site owner for further assistance.