问题描述
我管理其部署在JBoss 3.2.1 J2EE应用程序。至于我的客户我的服务的一部分,我想提供报告,其中显示活动会话的数量。我实现了一个简单的类和JSP网页,其中检索活动会话的数目,但我已经发现了一个漏洞:检查会议本身创建一个新的会话,因此膨胀的会话数数的过程
I manage a J2EE application which is deployed on JBoss 3.2.1. As part of my service to my client I want to provide reports which show the number of active sessions. I have implemented a simple class and a JSP page which retrieve the number of active sessions, but I have discovered a flaw: the process of checking the number of sessions itself creates a new session, and therefore inflates the number of sessions.
下面是code为我的类:
Here is the code for my class:
package com.hudsongates;
import javax.servlet.http.*;
public class SessionCount implements HttpSessionListener
{
private static int numberOfSessions = 0;
public void sessionCreated (HttpSessionEvent evt)
{
numberOfSessions++;
}
public void sessionDestroyed (HttpSessionEvent evt)
{
numberOfSessions--;
}
// here is our own method to return the number of current sessions
public static int getNumberOfSessions()
{
return numberOfSessions;
}
}
JSP页面看起来是这样的:
The JSP page looks like this:
<html>
<head>
<title>Active Sessions</title>
</head>
<body>
activeSessions=<%=com.hudsongates.SessionCount.getNumberOfSessions()%>
</body>
</html>
我想稍微改变这样的做法,而不是使用JSP页面,我用一个简单的批处理文件。例如,我创建了一个名为getSessions.bat一个批处理文件:
I would like to change the approach slightly so that instead of using a JSP page, I use a simple batch file. For example, I created a batch file called getSessions.bat:
REM Setup environment
call environment.bat
set LOG_PATH=%INSTALL_PATH%\log
set =%INSTALL_PATH%\lib\app.jar
set CLASSPATH=%INSTALL_PATH%\lib\app.jar
%JDK_HOME%\bin\java -cp "%CLASSPATH%" com.hudsongates.SessionCount.getNumberOfSessions() > %LOG_PATH%\test.log
问题是,当我执行批处理文件,我得到了以下异常:
The problem is that when I execute the batch file I get the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: com/hudsongates/SessionCount/getNumberOfSessions()
我需要一个主的方法添加到我的班?如果是的话,那会是什么?有没有实现的精确计算活动会话的数目我的最终目标的一个更好的办法?请记住,会话计数需要在下面的格式写入日志文件:
Do I need to add a "main" method to my class? If so, what would it do? Is there a better way of achieving my end goal of accurately counting the number of active sessions? Bear in mind that the session count needs to be written to a log file in the following format:
activeSessions=24
由于提前,
保
推荐答案
两种可能性映入脑海:
你的JSP可以被配置为不创建一个新的会话。
Two possibilities spring to mind:Your JSP can be configured to not create a new session. Stick this at the top of your JSP:
<%@ page session="false"%>
另外,写一个JMX MBean的它实现的JBoss的ServiceMBean接口,并将其部署为一个JBOS服务。这个MBean将查询会话数,并会出现的JBoss的JMX控制台上。您可以使用Web浏览器从那里监视它,而不与会话计数的干扰。
Alternatively, write a JMX MBean which implements JBoss's ServiceMBean interface, and deploy it as a JBos service. This MBean would query the session count, and would appear on JBoss's JMX console. You can use your web browser to monitor it from there, without interfering with your session count.
这篇关于指望部署在JBoss 3.2.1在J2EE应用程序的活动会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!