An interesting aspect of the PortletSession is the fact that data stored in the PortletSession, by default, is local and accessible only to the portlet instance that created it. By default, data stored in the PortletSession by one portlet instance cannot be shared by any other portlets on the same portal page. If there are four portlets on a portal page, if they all use a PortletSession object, then each one will have a separate, unshared, PortletSession namespace. Even if two instances of the same portlet appear on a portal page, each one will have its own, unshared, PortletSession namespace.
The misuse of session data is one of the most significant performance bottlenecks a portal server.
Cameron McKenzie, Editor of TheServerSide.com
Relationship to the Servlet API
Notice that we emphasize that each portlet instance will have its own PortletSession namespace, as opposed to saying that each portlet will have its own PortletSession. Behind the scenes, the PortletSession piggypbacks of the HttpSession from the underlying Servlet and JSP API. As a result, portlets packaged in the same WAR file will share an underlying HttpSession, while others will not.
Information is pulled out of the PortletSession using the getAttribute(String) method. Objects are put into the PortletSession using the setAttribute(String, Object) method. The name used to put an object into the session must exactly match the name used to pull the object out. Spellling mistakes, or even a different caSinG of letters will cause the return of a null object. Always try to avoid NullPointerExceptions.
Avoiding session bloat
The PortletSession also includes a method called removeAttribute(String). If you no longer have use for an object stored in the PortletSession, that object should be removed from the session to free up server based resources.
The misuse of session data is one of the most significant performance bottlenecks a portal server, or any Java EE application server for that matter, will encounter. Eliminating unnecessary objects from your PortletSession, and avoiding what is known as session bloat, will help you avoid performance problems at runtime.
How do you avoid performance problems on your portal server? Let us know.