Java 在使用ApacheGeronimo的简单Web服务中尝试使用基本身份验证时,为什么会出现巨大的内存泄漏

Java 在使用ApacheGeronimo的简单Web服务中尝试使用基本身份验证时,为什么会出现巨大的内存泄漏,java,web-services,memory-leaks,basic-authentication,geronimo,Java,Web Services,Memory Leaks,Basic Authentication,Geronimo,我使用的是Apache Gronimo 3.01,在使用基本身份验证的Web服务中发现了巨大的内存泄漏,如果不使用身份验证,则没有内存泄漏: 唯一的代码是: package org.apache.geronimo.samples.jws; import javax.annotation.Resource; import javax.jws.WebService; import javax.xml.ws.WebServiceContext; @WebService(serviceName =

我使用的是Apache Gronimo 3.01,在使用基本身份验证的Web服务中发现了巨大的内存泄漏,如果不使用身份验证,则没有内存泄漏:

唯一的代码是:

 package org.apache.geronimo.samples.jws;

import javax.annotation.Resource;
import javax.jws.WebService;
import javax.xml.ws.WebServiceContext;

@WebService(serviceName = "Calculator",
            portName="CalculatorPort",
            endpointInterface = "org.apache.geronimo.samples.jws.Calculator",
            targetNamespace = "http://jws.samples.geronimo.apache.org"
            )
public class CalculatorService implements Calculator {

    @Resource
    private WebServiceContext context;

    public int add(int value1, int value2) {
        System.out.println("User Principal: " + context.getUserPrincipal());
        return value1 + value2;
    }
}

以及以下XML:

jaxws计算器/WebContent/WEB-INF/WebContent/WEB.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  <display-name>jaxws-calculator</display-name>
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Protected</web-resource-name>
      <url-pattern>/*</url-pattern>
      <http-method>GET</http-method>
      <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
      <role-name>wsusers</role-name>
    </auth-constraint>
  </security-constraint>
  <login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>LeakyWsSecurityRealm</realm-name>
  </login-config>
  <security-role>
    <role-name>wsusers</role-name>
  </security-role>
  <servlet>
    <display-name>Apache-Axis Servlet</display-name>
    <servlet-name>AxisServlet</servlet-name>
    <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/servlet/AxisServlet</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>*.jws</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>
  <servlet>
    <display-name>Axis Admin Servlet</display-name>
    <servlet-name>AdminServlet</servlet-name>
    <servlet-class>org.apache.axis.transport.http.AdminServlet</servlet-class>
    <load-on-startup>100</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>AdminServlet</servlet-name>
    <url-pattern>/servlet/AdminServlet</url-pattern>
  </servlet-mapping>
</web-app>
jaxws计算器/WebContent/WEB-INF/WebContent/geronimo-WEB.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<web:web-app xmlns:app="http://geronimo.apache.org/xml/ns/j2ee/application-2.0" xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:client="http://geronimo.apache.org/xml/ns/j2ee/application-client-2.0" xmlns:conn="http://geronimo.apache.org/xml/ns/j2ee/connector-1.2" xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2" xmlns:ejb="http://openejb.apache.org/xml/ns/openejb-jar-2.2" xmlns:jaspi="http://geronimo.apache.org/xml/ns/geronimo-jaspi" xmlns:log="http://geronimo.apache.org/xml/ns/loginconfig-2.0" xmlns:name="http://geronimo.apache.org/xml/ns/naming-1.2" xmlns:pers="http://java.sun.com/xml/ns/persistence" xmlns:pkgen="http://openejb.apache.org/xml/ns/pkgen-2.1" xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0" xmlns:web="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1">
    <dep:environment>
        <dep:moduleId>
            <dep:groupId>leaky-ws</dep:groupId>
            <dep:artifactId>jaxws-calculator</dep:artifactId>
            <dep:version>1.0</dep:version>
            <dep:type>car</dep:type>
        </dep:moduleId>
    </dep:environment>
    <web:context-root>/jaxws-calculator</web:context-root>
    <web:security-realm-name>LeakyWsSecurityRealm</web:security-realm-name>
</web:web-app>
jaxws calculatorEAR/EarContent/META-INF/application.xml:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" id="Application_ID" version="6">
  <display-name>jaxws-calculatorEAR</display-name>
  <module>
    <web>
      <web-uri>jaxws-calculator.war</web-uri>
      <context-root>jaxws-calculator</context-root>
    </web>
  </module>
</application>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<app:application xmlns:app="http://geronimo.apache.org/xml/ns/j2ee/application-2.0" xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:client="http://geronimo.apache.org/xml/ns/j2ee/application-client-2.0" xmlns:conn="http://geronimo.apache.org/xml/ns/j2ee/connector-1.2" xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2" xmlns:ejb="http://openejb.apache.org/xml/ns/openejb-jar-2.2" xmlns:jaspi="http://geronimo.apache.org/xml/ns/geronimo-jaspi" xmlns:log="http://geronimo.apache.org/xml/ns/loginconfig-2.0" xmlns:name="http://geronimo.apache.org/xml/ns/naming-1.2" xmlns:pers="http://java.sun.com/xml/ns/persistence" xmlns:pkgen="http://openejb.apache.org/xml/ns/pkgen-2.1" xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0" xmlns:web="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1" application-name="ws-ivr">
    <dep:environment>
        <dep:moduleId>
            <dep:groupId>leaky-ws</dep:groupId>
            <dep:artifactId>jaxws-calculatorEAR</dep:artifactId>
            <dep:version>1.0</dep:version>
            <dep:type>car</dep:type>
        </dep:moduleId>
        <dep:dependencies>
            <dep:dependency>
                <dep:groupId>console.realm</dep:groupId>
                <dep:artifactId>LeakyWsSecurityRealm</dep:artifactId>
            </dep:dependency>
        </dep:dependencies>
    </dep:environment>
    <sec:security>
        <sec:role-mappings>
            <sec:role role-name="wsusers">
                <sec:principal class="org.apache.geronimo.security.realm.providers.GeronimoGroupPrincipal" name="wsusers"/> 
            </sec:role>
        </sec:role-mappings>
    </sec:security>
</app:application>
jaxws calculatorEAR/EarContent/META-INF/geronimo-application.xml:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" id="Application_ID" version="6">
  <display-name>jaxws-calculatorEAR</display-name>
  <module>
    <web>
      <web-uri>jaxws-calculator.war</web-uri>
      <context-root>jaxws-calculator</context-root>
    </web>
  </module>
</application>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<app:application xmlns:app="http://geronimo.apache.org/xml/ns/j2ee/application-2.0" xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:client="http://geronimo.apache.org/xml/ns/j2ee/application-client-2.0" xmlns:conn="http://geronimo.apache.org/xml/ns/j2ee/connector-1.2" xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2" xmlns:ejb="http://openejb.apache.org/xml/ns/openejb-jar-2.2" xmlns:jaspi="http://geronimo.apache.org/xml/ns/geronimo-jaspi" xmlns:log="http://geronimo.apache.org/xml/ns/loginconfig-2.0" xmlns:name="http://geronimo.apache.org/xml/ns/naming-1.2" xmlns:pers="http://java.sun.com/xml/ns/persistence" xmlns:pkgen="http://openejb.apache.org/xml/ns/pkgen-2.1" xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0" xmlns:web="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1" application-name="ws-ivr">
    <dep:environment>
        <dep:moduleId>
            <dep:groupId>leaky-ws</dep:groupId>
            <dep:artifactId>jaxws-calculatorEAR</dep:artifactId>
            <dep:version>1.0</dep:version>
            <dep:type>car</dep:type>
        </dep:moduleId>
        <dep:dependencies>
            <dep:dependency>
                <dep:groupId>console.realm</dep:groupId>
                <dep:artifactId>LeakyWsSecurityRealm</dep:artifactId>
            </dep:dependency>
        </dep:dependencies>
    </dep:environment>
    <sec:security>
        <sec:role-mappings>
            <sec:role role-name="wsusers">
                <sec:principal class="org.apache.geronimo.security.realm.providers.GeronimoGroupPrincipal" name="wsusers"/> 
            </sec:role>
        </sec:role-mappings>
    </sec:security>
</app:application>
在geronimo的控制台中,我设置了一个安全域:LeakyWsSecurityRealm,它是一个属性文件域

问题在于,正如我在使用VisualVM时看到的那样,它在64K实例org.apache.geronimo.security.Context引用的OutOfMemoryError之前泄漏了java.security.AccessControlContext 128K类型的对象


有人知道这里出了什么问题吗?

一旦使用了上下文,您不需要对它做些什么吗?还是由Geronimo为您处理它?我想我不知道,上面的java代码取自Apache Geronimo的一个示例,没有清理。但我是JavaEE的新手,所以我可能错了。。。