0 0

flex+blazeds+java session自动消毁怎么解决25

系统当中配置SessionListener,session刚被创建 一分钟不到就自动消毁了。(注意是自动消毁的)

直接看代码

web.xml配置

<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<listener>
		<description>系统初始化</description>
		<listener-class>com.zznode.iptvs.core.StartupListener</listener-class>
	</listener>

	<listener>
		<description>FlexSessionListener</description>
		<listener-class>com.zznode.iptvs.core.listener.SessionListener</listener-class>
	</listener>


	<!-- flex session -->
	<listener>
		<listener-class>flex.messaging.HttpFlexSession</listener-class>
	</listener>

	<!-- Flex 配置 -->
	<servlet>
		<servlet-name>Flex</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>Flex</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>


java类SessionListener


public class SessionListener implements HttpSessionListener{
	
	private static final Logger logger = Logger.getLogger(SessionListener.class);

	/**
	 * Session创建
	 */
	public void sessionCreated(HttpSessionEvent arg0) {
		logger.info("flexSession is created and FlexSession id is " + arg0.getSession().getId());
	}

	/**
	 * Session消毁处理
	 */
	public void sessionDestroyed(HttpSessionEvent arg0) {
		HttpSession session = arg0.getSession();
		logger.info("flexSession is destroyed and FlexSession id is " + session.getId());
		SysUserInfo user = (SysUserInfo) session.getAttribute(GlobalSysInfo.USER_FLAG);
		if(user != null){
			logger.info(" userName is " + user.getUsername());
			GlobalSysInfo.removeOnlineMaps(user.getId());
		}
		
		
	}

}



超时校验
import flex.messaging.FlexContext;

public class TimeOutInterceptor {

	public Object before(ProceedingJoinPoint point)	throws Throwable {
		
		SysUserInfo user = (SysUserInfo) FlexContext.getHttpRequest().getSession().getAttribute(GlobalSysInfo.USER_FLAG);
		if(user != null){
			return point.proceed();
		}else{
			throw new ZznodeException(GlobalSysInfo.errorCodeMap.get(SystemConstants.SESSIONOUT));
		}
//		return point.proceed();
	}

}


我登录界面是html,其它页面是flex
现在服务器一会儿就超时。一会就超时。这个超时时间好像是随机的。有可能十多分钟。有可能是默认的半小时,有的时候甚至一分钟或几秒钟就。
下面是session被创建和销毁的日志
2012-03-13 11:04:52 [http-bio-8008-exec-36]   [INFO] - flexSession is created and FlexSession id is 2285DC5AC212E0EE6C8D32DDD6073B12
2012-03-13 11:05:04 [http-bio-8008-exec-36]   [INFO] - flexSession is destroyed and FlexSession id is 2285DC5AC212E0EE6C8D32DDD6073B12
2012-03-13 11:05:06 [http-bio-8008-exec-36]   [INFO] - flexSession is created and FlexSession id is 3CBBB80C9675E35CBD270209553ED857
2012-03-13 11:11:46 [http-bio-8008-exec-45]   [INFO] - flexSession is created and FlexSession id is 9777A2EACDEC3739C7C35DA4010ADAE1
2012-03-13 11:11:46 [http-bio-8008-exec-45]   [INFO] - flexSession is destroyed and FlexSession id is 9777A2EACDEC3739C7C35DA4010ADAE1
2012-03-13 11:11:51 [http-bio-8008-exec-45]   [INFO] - flexSession is created and FlexSession id is FF55C0EB47DE4527D56A69A53682098B
2012-03-13 11:13:52 [ContainerBackgroundProcessor[StandardEngine[Catalina]]   [INFO] - flexSession is destroyed and FlexSession id is 05ACB7CFE66D28DFCB302A47F8757095
2012-03-13 11:13:52 [ContainerBackgroundProcessor[StandardEngine[Catalina]]   [INFO] -  userName is admin
2012-03-13 11:13:52 [ContainerBackgroundProcessor[StandardEngine[Catalina]]   [INFO] - flexSession is destroyed and FlexSession id is FF55C0EB47DE4527D56A69A53682098B
2012-03-13 11:13:52 [ContainerBackgroundProcessor[StandardEngine[Catalina]]   [INFO] -  userName is admin


注意大家看一下。session 日志。有的session刚被创建就销毁了。而有的又正常。请各位大牛给出原因和解决方式。如果满意的话的我再追加分数
2012年3月13日 13:58

2个答案 按时间排序 按投票排序

0 0

你把你的HttpSessionListener替换成ServletContextListener,然后在实现ServletContextListener里面的 sessionCreated和sessionDestroyed方法里面写你的业务然后,  再来试试

2012年3月29日 08:54
0 0

是不是你的代码里有主动关闭SESSION的地方?

2012年3月13日 23:05

相关推荐

Global site tag (gtag.js) - Google Analytics