org.apache.catalina.ServerFactory.getServer()Tomcat 7中的等价物或者检索org.apache.catalina.Session实例的最佳方法是什么?
以下是用于处理Tomcat 6.0的示例代码:
public List<org.apache.catalina.Session> findActiveSessions() throws ServiceException {
StandardEngine engine = (StandardEngine) ServerFactory.getServer().findService("Catalina").getContainer();
StandardContext context = (StandardContext) engine.findChild(engine.getDefaultHost())
.findChild(ServletActionContext.getServletContext().getContextPath());
List<org.apache.catalina.Session> list = new ArrayList<org.apache.catalina.Session>();
for (org.apache.catalina.Session session : context.getManager().findSessions()) {
list.add(session);
}
return list;
}
Run Code Online (Sandbox Code Playgroud)
小智 18
您可以通过其管理注册查找..
import javax.management.*;
import org.apache.catalina.Server;
MBeanServer mBeanServer = MBeanServerFactory.findMBeanServer(null).get(0);
ObjectName name = new ObjectName("Catalina", "type", "Server");
Server server = (Server) mBeanServer.getAttribute(name, "managedResource");
Run Code Online (Sandbox Code Playgroud)
显然,代码没有错误检查但功能正常.
| 归档时间: |
|
| 查看次数: |
8014 次 |
| 最近记录: |