litesoft
@ 947
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 31 |
// This Source Code is in the Public Domain per: http://unlicense.org 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; } } |