Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package org.litesoft.servlets;

import javax.servlet.http.*;

public class HttpSessionHelper
{
    public interface Factory
    {
        Object create();
    }

    public static Object get( HttpSession pSession, Factory pFactory, String pAttribute )
    {
        Object zObject = pSession.getAttribute( pAttribute );
        if ( null == zObject )
        {
            // Quazy double check lock should two browser instances w/ the same Session
            // attempt to create the Attribute at the "same" time!
            //noinspection SynchronizationOnLocalVariableOrMethodParameter
            synchronized ( pAttribute )
            {
                if ( null == (zObject = pSession.getAttribute( pAttribute )) )
                {
                    pSession.setAttribute( pAttribute, zObject = pFactory.create() );
                }
            }
        }
        return zObject;
    }
}

Commits for litesoft/trunk/Java/core/Server/src/org/litesoft/servlets/HttpSessionHelper.java

Diff revisions: vs.
Revision Author Commited Message
2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000