首页 文章

Spring Boot应用程序缓慢内存泄漏

提问于
浏览
2

我最近部署了一个Spring Boot应用程序,该应用程序计划每天运行,以便从Cassandra集群解析新数据 . 经过大约20个小时的工作(对Cassandra进行了数百万次读/写访问),出现了一些内存问题,并且在每次迭代时(异常都在循环内捕获)我有这样的错误:

java.lang.RuntimeException: java.lang.IllegalStateException: java.lang.reflect.InvocationTargetException
    at org.springframework.data.mapping.model.ClassGeneratingPropertyAccessorFactory.createAccessorClass(ClassGeneratingPropertyAccessorFactory.java:170)
    at org.springframework.data.mapping.model.ClassGeneratingPropertyAccessorFactory.potentiallyCreateAndRegisterPersistentPropertyAccessorClass(ClassGeneratingPropertyAccessorFactory.java:154)
    at org.springframework.data.mapping.model.ClassGeneratingPropertyAccessorFactory.getPropertyAccessor(ClassGeneratingPropertyAccessorFactory.java:80)
    at org.springframework.data.mapping.model.BasicPersistentEntity.getPropertyAccessor(BasicPersistentEntity.java:425)
    at org.springframework.data.cassandra.convert.MappingCassandraConverter.getConvertingAccessor(MappingCassandraConverter.java:611)
    at org.springframework.data.cassandra.convert.MappingCassandraConverter.readEntityFromRow(MappingCassandraConverter.java:172)
    at org.springframework.data.cassandra.convert.MappingCassandraConverter.readRow(MappingCassandraConverter.java:149)
    at com.myapp.utils.CassandraIterable$1.next(CassandraIterable.java:35)
    at com.myapp.service.packer.PositionParsingService.parse(PositionParsingService.java:60)
    at com.myapp.service.packer.PositionLoadService.update(PositionLoadService.java:202)
    at com.myapp.service.packer.PositionLoadService.updateVehicle(PositionLoadService.java:129)
    at com.myapp.service.packer.PositionLoadService.updateAllVehicles(PositionLoadService.java:99)
    at com.myapp.service.packer.PositionLoadService.updateAllVehicles(PositionLoadService.java:84)
    at com.myapp.service.packer.PositionLoadService$$FastClassBySpringCGLIB$$2605bc6c.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:721)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.aop.interceptor.AsyncExecutionInterceptor$1.call(AsyncExecutionInterceptor.java:115)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: java.lang.reflect.InvocationTargetException
    at org.springframework.data.mapping.model.ClassGeneratingPropertyAccessorFactory$Evil.defineClass(ClassGeneratingPropertyAccessorFactory.java:1480)
    at org.springframework.data.mapping.model.ClassGeneratingPropertyAccessorFactory$PropertyAccessorClassGenerator.generateCustomAccessorClass(ClassGeneratingPropertyAccessorFactory.java:282)
    at org.springframework.data.mapping.model.ClassGeneratingPropertyAccessorFactory.createAccessorClass(ClassGeneratingPropertyAccessorFactory.java:168)
    ... 21 common frames omitted
Caused by: java.lang.reflect.InvocationTargetException: null
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.data.mapping.model.ClassGeneratingPropertyAccessorFactory$Evil.defineClass(ClassGeneratingPropertyAccessorFactory.java:1476)
    ... 23 common frames omitted
Caused by: java.lang.OutOfMemoryError: Compressed class space
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    ... 28 common frames omitted

通过分析问题发生后产生的内存转储,我有这样的报告:

Retained

Detail

从Java任务控制,运行垃圾收集后,我得到:

Memory usage

我不认为我的代码直接负责泄漏,即使可能有某些东西在它应该发布时没有发布或者可能存在我忽略的配置问题 .

我尝试将Java从JDK SE 8u60升级到8u121并将Spring启动升级到版本1.5.2.RELEASE . 这是依赖项的完整列表:

com.myapp:jar:0.0.1-SNAPSHOT
+- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.5.2.RELEASE:compile
|  +- org.springframework.boot:spring-boot-starter:jar:1.5.2.RELEASE:compile
|  |  +- (org.springframework.boot:spring-boot:jar:1.5.2.RELEASE:compile - omitted for duplicate)
|  |  +- (org.springframework.boot:spring-boot-autoconfigure:jar:1.5.2.RELEASE:compile - omitted for duplicate)
|  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.5.2.RELEASE:compile
|  |  |  +- ch.qos.logback:logback-classic:jar:1.1.11:compile
|  |  |  |  +- ch.qos.logback:logback-core:jar:1.1.11:compile
|  |  |  |  \- (org.slf4j:slf4j-api:jar:1.7.24:compile - version managed from 1.7.22; omitted for duplicate)
|  |  |  +- org.slf4j:jcl-over-slf4j:jar:1.7.24:compile
|  |  |  |  \- (org.slf4j:slf4j-api:jar:1.7.24:compile - version managed from 1.7.22; omitted for duplicate)
|  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.24:compile
|  |  |  |  \- (org.slf4j:slf4j-api:jar:1.7.24:compile - version managed from 1.7.22; omitted for duplicate)
|  |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.24:compile
|  |  |     \- (org.slf4j:slf4j-api:jar:1.7.24:compile - version managed from 1.7.22; omitted for duplicate)
|  |  +- org.springframework:spring-core:jar:4.3.7.RELEASE:compile
|  |  \- org.yaml:snakeyaml:jar:1.17:runtime
|  +- org.springframework.boot:spring-boot-starter-aop:jar:1.5.2.RELEASE:compile
|  |  +- (org.springframework.boot:spring-boot-starter:jar:1.5.2.RELEASE:compile - omitted for duplicate)
|  |  +- org.springframework:spring-aop:jar:4.3.7.RELEASE:compile
|  |  |  +- (org.springframework:spring-beans:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  |  |  \- (org.springframework:spring-core:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  |  \- org.aspectj:aspectjweaver:jar:1.8.9:compile
|  +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.5.2.RELEASE:compile
|  |  +- (org.springframework.boot:spring-boot-starter:jar:1.5.2.RELEASE:compile - omitted for duplicate)
|  |  +- org.apache.tomcat:tomcat-jdbc:jar:8.5.11:compile
|  |  |  \- org.apache.tomcat:tomcat-juli:jar:8.5.11:compile
|  |  \- org.springframework:spring-jdbc:jar:4.3.7.RELEASE:compile
|  |     +- (org.springframework:spring-beans:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  |     +- (org.springframework:spring-core:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  |     \- (org.springframework:spring-tx:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  +- org.hibernate:hibernate-core:jar:5.0.12.Final:compile
|  |  +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
|  |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
|  |  +- org.javassist:javassist:jar:3.21.0-GA:compile (version managed from 3.18.1-GA)
|  |  +- antlr:antlr:jar:2.7.7:compile
|  |  +- org.jboss:jandex:jar:2.0.0.Final:compile
|  |  +- dom4j:dom4j:jar:1.6.1:compile
|  |  \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
|  |     \- (org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile - omitted for duplicate)
|  +- org.hibernate:hibernate-entitymanager:jar:5.0.12.Final:compile
|  |  +- (org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile - omitted for duplicate)
|  |  +- (org.hibernate:hibernate-core:jar:5.0.12.Final:compile - omitted for duplicate)
|  |  +- (dom4j:dom4j:jar:1.6.1:compile - omitted for duplicate)
|  |  +- (org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile - omitted for duplicate)
|  |  +- (org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile - omitted for duplicate)
|  |  \- (org.javassist:javassist:jar:3.21.0-GA:compile - version managed from 3.18.1-GA; omitted for duplicate)
|  +- javax.transaction:javax.transaction-api:jar:1.2:compile
|  +- org.springframework.data:spring-data-jpa:jar:1.11.1.RELEASE:compile
|  |  +- org.springframework.data:spring-data-commons:jar:1.13.1.RELEASE:compile
|  |  |  +- (org.springframework:spring-core:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  |  |  +- (org.springframework:spring-beans:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  |  |  +- (org.slf4j:slf4j-api:jar:1.7.24:compile - version managed from 1.7.22; omitted for duplicate)
|  |  |  \- (org.slf4j:jcl-over-slf4j:jar:1.7.24:runtime - omitted for duplicate)
|  |  +- org.springframework:spring-orm:jar:4.3.7.RELEASE:compile
|  |  |  +- (org.springframework:spring-beans:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  |  |  +- (org.springframework:spring-core:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  |  |  +- (org.springframework:spring-jdbc:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  |  |  \- (org.springframework:spring-tx:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  |  +- org.springframework:spring-context:jar:4.3.7.RELEASE:compile
|  |  |  +- (org.springframework:spring-aop:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  |  |  +- (org.springframework:spring-beans:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  |  |  +- (org.springframework:spring-core:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  |  |  \- (org.springframework:spring-expression:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  |  +- (org.springframework:spring-aop:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  |  +- (org.springframework:spring-tx:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  |  +- org.springframework:spring-beans:jar:4.3.7.RELEASE:compile
|  |  |  \- (org.springframework:spring-core:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  |  +- (org.springframework:spring-core:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  |  +- org.slf4j:slf4j-api:jar:1.7.24:compile
|  |  \- (org.slf4j:jcl-over-slf4j:jar:1.7.24:compile - scope updated from runtime; omitted for duplicate)
|  \- org.springframework:spring-aspects:jar:4.3.7.RELEASE:compile
|     \- (org.aspectj:aspectjweaver:jar:1.8.9:compile - omitted for duplicate)
+- org.springframework.boot:spring-boot-starter-web:jar:1.5.2.RELEASE:compile
|  +- (org.springframework.boot:spring-boot-starter:jar:1.5.2.RELEASE:compile - omitted for duplicate)
|  +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.5.2.RELEASE:compile
|  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.11:compile
|  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.11:compile
|  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.11:compile
|  |     \- (org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.11:compile - omitted for duplicate)
|  +- org.hibernate:hibernate-validator:jar:5.3.4.Final:compile
|  |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
|  |  +- (org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile - omitted for duplicate)
|  |  \- com.fasterxml:classmate:jar:1.3.3:compile (version managed from 1.3.1)
|  +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.7:compile
|  |  +- (com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile - omitted for duplicate)
|  |  \- (com.fasterxml.jackson.core:jackson-core:jar:2.8.7:compile - omitted for duplicate)
|  +- org.springframework:spring-web:jar:4.3.7.RELEASE:compile
|  |  +- (org.springframework:spring-aop:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  |  +- (org.springframework:spring-beans:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  |  +- (org.springframework:spring-context:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  |  \- (org.springframework:spring-core:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  \- org.springframework:spring-webmvc:jar:4.3.7.RELEASE:compile
|     +- (org.springframework:spring-aop:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|     +- (org.springframework:spring-beans:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|     +- (org.springframework:spring-context:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|     +- (org.springframework:spring-core:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|     +- org.springframework:spring-expression:jar:4.3.7.RELEASE:compile
|     |  \- (org.springframework:spring-core:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|     \- (org.springframework:spring-web:jar:4.3.7.RELEASE:compile - omitted for duplicate)
+- org.springframework.boot:spring-boot-starter-data-cassandra:jar:1.5.2.RELEASE:compile
|  +- (org.springframework.boot:spring-boot-starter:jar:1.5.2.RELEASE:compile - omitted for duplicate)
|  +- org.springframework:spring-tx:jar:4.3.7.RELEASE:compile
|  |  +- (org.springframework:spring-beans:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  |  \- (org.springframework:spring-core:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  \- org.springframework.data:spring-data-cassandra:jar:1.5.1.RELEASE:compile
|     +- org.springframework.data:spring-cql:jar:1.5.1.RELEASE:compile
|     |  +- (org.springframework:spring-context:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|     |  +- (org.springframework:spring-beans:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|     |  +- (org.springframework:spring-core:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|     |  +- (org.springframework:spring-expression:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|     |  +- (org.springframework:spring-tx:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|     |  +- (org.springframework.data:spring-data-commons:jar:1.13.1.RELEASE:compile - omitted for duplicate)
|     |  +- (com.datastax.cassandra:cassandra-driver-core:jar:3.1.4:compile - version managed from 3.1.3; omitted for duplicate)
|     |  +- (com.google.guava:guava:jar:19.0:compile - omitted for conflict with 16.0.1)
|     |  +- (org.slf4j:slf4j-api:jar:1.7.24:compile - version managed from 1.7.7; omitted for duplicate)
|     |  \- (org.slf4j:jcl-over-slf4j:jar:1.7.24:runtime - omitted for duplicate)
|     +- (org.springframework:spring-expression:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|     +- (org.springframework.data:spring-data-commons:jar:1.13.1.RELEASE:compile - omitted for duplicate)
|     +- (com.datastax.cassandra:cassandra-driver-core:jar:3.1.4:compile - version managed from 3.1.3; omitted for duplicate)
|     +- (org.slf4j:slf4j-api:jar:1.7.24:compile - version managed from 1.7.7; omitted for duplicate)
|     \- (org.slf4j:jcl-over-slf4j:jar:1.7.24:compile - scope updated from runtime; omitted for duplicate)
+- org.springframework.boot:spring-boot-devtools:jar:1.5.2.RELEASE:compile
|  +- org.springframework.boot:spring-boot:jar:1.5.2.RELEASE:compile
|  |  +- (org.springframework:spring-core:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  |  \- (org.springframework:spring-context:jar:4.3.7.RELEASE:compile - omitted for duplicate)
|  \- org.springframework.boot:spring-boot-autoconfigure:jar:1.5.2.RELEASE:compile
|     \- (org.springframework.boot:spring-boot:jar:1.5.2.RELEASE:compile - omitted for duplicate)
+- com.datastax.cassandra:cassandra-driver-mapping:jar:3.1.4:compile
|  \- com.datastax.cassandra:cassandra-driver-core:jar:3.1.4:compile
|     +- io.netty:netty-handler:jar:4.0.37.Final:compile
|     |  +- io.netty:netty-buffer:jar:4.0.37.Final:compile
|     |  |  \- io.netty:netty-common:jar:4.0.37.Final:compile
|     |  +- io.netty:netty-transport:jar:4.0.37.Final:compile
|     |  |  \- (io.netty:netty-buffer:jar:4.0.37.Final:compile - omitted for duplicate)
|     |  \- io.netty:netty-codec:jar:4.0.37.Final:compile
|     |     \- (io.netty:netty-transport:jar:4.0.37.Final:compile - omitted for duplicate)
|     +- com.google.guava:guava:jar:16.0.1:compile
|     +- io.dropwizard.metrics:metrics-core:jar:3.1.3:compile (version managed from 3.1.2)
|     |  \- (org.slf4j:slf4j-api:jar:1.7.24:compile - version managed from 1.7.7; omitted for duplicate)
|     +- com.github.jnr:jnr-ffi:jar:2.0.7:compile
|     |  +- com.github.jnr:jffi:jar:1.2.10:compile
|     |  +- com.github.jnr:jffi:jar:native:1.2.10:runtime
|     |  +- org.ow2.asm:asm:jar:5.0.3:compile
|     |  +- org.ow2.asm:asm-commons:jar:5.0.3:compile
|     |  |  \- (org.ow2.asm:asm-tree:jar:5.0.3:compile - omitted for duplicate)
|     |  +- org.ow2.asm:asm-analysis:jar:5.0.3:compile
|     |  |  \- (org.ow2.asm:asm-tree:jar:5.0.3:compile - omitted for duplicate)
|     |  +- org.ow2.asm:asm-tree:jar:5.0.3:compile
|     |  |  \- (org.ow2.asm:asm:jar:5.0.3:compile - omitted for duplicate)
|     |  +- org.ow2.asm:asm-util:jar:5.0.3:compile
|     |  |  \- (org.ow2.asm:asm-tree:jar:5.0.3:compile - omitted for duplicate)
|     |  \- com.github.jnr:jnr-x86asm:jar:1.0.2:compile
|     \- com.github.jnr:jnr-posix:jar:3.0.27:compile
|        +- (com.github.jnr:jnr-ffi:jar:2.0.7:compile - omitted for duplicate)
|        \- com.github.jnr:jnr-constants:jar:0.9.0:compile
+- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.8.7:compile
|  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile
|  +- com.fasterxml.jackson.core:jackson-core:jar:2.8.7:compile
|  \- (com.fasterxml.jackson.core:jackson-databind:jar:2.8.7:compile - omitted for duplicate)
+- com.oracle.jdbc:ojdbc7:jar:12.1.0.2:compile
|  +- com.oracle.jdbc:xdb6:jar:12.1.0.2:compile
|  +- com.oracle.jdbc:orai18n:jar:12.1.0.2:compile
|  +- com.oracle.jdbc:xmlparserv2:jar:12.1.0.2:compile
|  +- com.oracle.jdbc:oraclepki:jar:12.1.0.2:compile
|  +- com.oracle.jdbc:osdt_cert:jar:12.1.0.2:compile
|  \- com.oracle.jdbc:osdt_core:jar:12.1.0.2:compile
+- com.mycompany:Pandora-json:jar:2.1.0-SNAPSHOT:compile
|  +- (com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile - version managed from 2.5.4; omitted for duplicate)
|  +- (com.fasterxml.jackson.core:jackson-databind:jar:2.8.7:compile - version managed from 2.5.4; omitted for duplicate)
|  +- com.fasterxml.jackson.datatype:jackson-datatype-joda:jar:2.8.7:compile (version managed from 2.5.4)
|  |  +- (com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile - version managed from 2.5.4; omitted for duplicate)
|  |  +- (com.fasterxml.jackson.core:jackson-core:jar:2.8.7:compile - omitted for duplicate)
|  |  +- (com.fasterxml.jackson.core:jackson-databind:jar:2.8.7:compile - version managed from 2.5.4; omitted for duplicate)
|  |  \- (joda-time:joda-time:jar:2.9.7:compile - version managed from 2.7; omitted for duplicate)
|  \- com.fasterxml.jackson.datatype:jackson-datatype-guava:jar:2.8.7:compile (version managed from 2.4.0)
|     +- (com.fasterxml.jackson.core:jackson-databind:jar:2.8.7:compile - version managed from 2.5.4; omitted for duplicate)
|     +- (com.fasterxml.jackson.core:jackson-core:jar:2.8.7:compile - omitted for duplicate)
|     \- (com.google.guava:guava:jar:16.0:compile - omitted for conflict with 16.0.1)
+- javax.inject:javax.inject:jar:1:compile
+- joda-time:joda-time:jar:2.9.7:compile
+- org.projectlombok:lombok:jar:1.16.14:compile
+- org.springframework.boot:spring-boot-starter-test:jar:1.5.2.RELEASE:test
|  +- org.springframework.boot:spring-boot-test:jar:1.5.2.RELEASE:test
|  |  \- (org.springframework.boot:spring-boot:jar:1.5.2.RELEASE:test - omitted for duplicate)
|  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:1.5.2.RELEASE:test
|  |  +- (org.springframework.boot:spring-boot-test:jar:1.5.2.RELEASE:test - omitted for duplicate)
|  |  \- (org.springframework.boot:spring-boot-autoconfigure:jar:1.5.2.RELEASE:test - omitted for duplicate)
|  +- com.jayway.jsonpath:json-path:jar:2.2.0:test
|  |  +- net.minidev:json-smart:jar:2.2.1:test
|  |  |  \- net.minidev:accessors-smart:jar:1.1:test
|  |  |     \- (org.ow2.asm:asm:jar:5.0.3:test - omitted for duplicate)
|  |  \- (org.slf4j:slf4j-api:jar:1.7.24:test - version managed from 1.7.16; omitted for duplicate)
|  +- junit:junit:jar:4.12:test
|  |  \- (org.hamcrest:hamcrest-core:jar:1.3:test - version managed from 1.1; omitted for duplicate)
|  +- (org.assertj:assertj-core:jar:2.6.0:test - omitted for conflict with 3.6.2)
|  +- org.mockito:mockito-core:jar:1.10.19:test
|  |  +- (org.hamcrest:hamcrest-core:jar:1.3:test - version managed from 1.1; omitted for duplicate)
|  |  \- org.objenesis:objenesis:jar:2.1:test
|  +- org.hamcrest:hamcrest-core:jar:1.3:test
|  +- org.hamcrest:hamcrest-library:jar:1.3:test
|  |  \- (org.hamcrest:hamcrest-core:jar:1.3:test - version managed from 1.1; omitted for duplicate)
|  +- org.skyscreamer:jsonassert:jar:1.4.0:test
|  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
|  +- (org.springframework:spring-core:jar:4.3.7.RELEASE:compile - scope updated from test; omitted for duplicate)
|  \- org.springframework:spring-test:jar:4.3.7.RELEASE:test
|     \- (org.springframework:spring-core:jar:4.3.7.RELEASE:test - omitted for duplicate)
+- commons-lang:commons-lang:jar:2.2:compile
+- org.assertj:assertj-core:jar:3.6.2:compile
+- org.mockito:mockito-all:jar:1.10.19:test
+- net.sourceforge.dynamicreports:dynamicreports-core:jar:4.1.1:compile
|  +- net.sf.jasperreports:jasperreports:jar:6.2.2:compile
|  |  +- commons-beanutils:commons-beanutils:jar:1.9.3:compile (version managed from 1.9.0)
|  |  |  \- (commons-collections:commons-collections:jar:3.2.2:compile - omitted for duplicate)
|  |  +- commons-collections:commons-collections:jar:3.2.2:compile
|  |  +- commons-digester:commons-digester:jar:2.1:compile
|  |  |  \- (commons-beanutils:commons-beanutils:jar:1.9.3:compile - version managed from 1.8.3; omitted for duplicate)
|  |  +- commons-logging:commons-logging:jar:1.1.1:compile
|  |  +- com.lowagie:itext:jar:2.1.7.js5:compile
|  |  |  \- bouncycastle:bcprov-jdk14:jar:138:compile
|  |  +- org.jfree:jcommon:jar:1.0.23:compile
|  |  +- org.jfree:jfreechart:jar:1.0.19:compile
|  |  |  \- (org.jfree:jcommon:jar:1.0.23:compile - omitted for duplicate)
|  |  +- org.eclipse.jdt.core.compiler:ecj:jar:4.3.1:compile
|  |  +- (com.fasterxml.jackson.core:jackson-core:jar:2.8.7:compile - version managed from 2.1.4; omitted for duplicate)
|  |  +- (com.fasterxml.jackson.core:jackson-databind:jar:2.8.7:compile - version managed from 2.1.4; omitted for duplicate)
|  |  +- (com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile - version managed from 2.1.4; omitted for duplicate)
|  |  \- com.google.zxing:core:jar:2.3.0:compile
|  +- org.apache.commons:commons-lang3:jar:3.1:compile
|  +- net.sf.barcode4j:barcode4j:jar:2.0:compile
|  |  +- avalon-framework:avalon-framework-impl:jar:4.2.0:compile
|  |  \- xml-apis:xml-apis:jar:1.4.01:compile (version managed from 1.3.04)
|  \- org.apache.xmlgraphics:batik-bridge:jar:1.8:compile
|     +- org.apache.xmlgraphics:batik-anim:jar:1.8:compile
|     |  +- (org.apache.xmlgraphics:batik-awt-util:jar:1.8:compile - omitted for duplicate)
|     |  +- (org.apache.xmlgraphics:batik-css:jar:1.8:compile - omitted for duplicate)
|     |  +- (org.apache.xmlgraphics:batik-dom:jar:1.8:compile - omitted for duplicate)
|     |  +- (org.apache.xmlgraphics:batik-ext:jar:1.8:compile - omitted for duplicate)
|     |  +- (org.apache.xmlgraphics:batik-parser:jar:1.8:compile - omitted for duplicate)
|     |  +- (org.apache.xmlgraphics:batik-svg-dom:jar:1.8:compile - omitted for duplicate)
|     |  +- (org.apache.xmlgraphics:batik-util:jar:1.8:compile - omitted for duplicate)
|     |  +- (xml-apis:xml-apis:jar:1.4.01:compile - version managed from 1.3.04; omitted for duplicate)
|     |  \- (xml-apis:xml-apis-ext:jar:1.3.04:compile - omitted for duplicate)
|     +- org.apache.xmlgraphics:batik-awt-util:jar:1.8:compile
|     |  \- (org.apache.xmlgraphics:batik-util:jar:1.8:compile - omitted for duplicate)
|     +- org.apache.xmlgraphics:batik-css:jar:1.8:compile
|     |  +- (org.apache.xmlgraphics:batik-ext:jar:1.8:compile - omitted for duplicate)
|     |  +- (org.apache.xmlgraphics:batik-util:jar:1.8:compile - omitted for duplicate)
|     |  +- (xml-apis:xml-apis:jar:1.4.01:compile - version managed from 1.3.04; omitted for duplicate)
|     |  \- (xml-apis:xml-apis-ext:jar:1.3.04:compile - omitted for duplicate)
|     +- org.apache.xmlgraphics:batik-dom:jar:1.8:compile
|     |  +- (org.apache.xmlgraphics:batik-css:jar:1.8:compile - omitted for duplicate)
|     |  +- (org.apache.xmlgraphics:batik-ext:jar:1.8:compile - omitted for duplicate)
|     |  +- (org.apache.xmlgraphics:batik-util:jar:1.8:compile - omitted for duplicate)
|     |  +- (org.apache.xmlgraphics:batik-xml:jar:1.8:compile - omitted for duplicate)
|     |  +- (xml-apis:xml-apis:jar:1.4.01:compile - version managed from 1.3.04; omitted for duplicate)
|     |  \- (xml-apis:xml-apis-ext:jar:1.3.04:compile - omitted for duplicate)
|     +- org.apache.xmlgraphics:batik-ext:jar:1.8:compile
|     |  \- (xml-apis:xml-apis:jar:1.4.01:compile - version managed from 1.3.04; omitted for duplicate)
|     +- org.apache.xmlgraphics:batik-gvt:jar:1.8:compile
|     |  +- (org.apache.xmlgraphics:batik-awt-util:jar:1.8:compile - omitted for duplicate)
|     |  \- (org.apache.xmlgraphics:batik-util:jar:1.8:compile - omitted for duplicate)
|     +- org.apache.xmlgraphics:batik-parser:jar:1.8:compile
|     |  +- (org.apache.xmlgraphics:batik-awt-util:jar:1.8:compile - omitted for duplicate)
|     |  +- (org.apache.xmlgraphics:batik-util:jar:1.8:compile - omitted for duplicate)
|     |  +- (org.apache.xmlgraphics:batik-xml:jar:1.8:compile - omitted for duplicate)
|     |  \- (xml-apis:xml-apis:jar:1.4.01:compile - version managed from 1.3.04; omitted for duplicate)
|     +- org.apache.xmlgraphics:batik-script:jar:1.8:compile
|     |  +- (org.apache.xmlgraphics:batik-anim:jar:1.8:compile - omitted for duplicate)
|     |  +- (org.apache.xmlgraphics:batik-util:jar:1.8:compile - omitted for duplicate)
|     |  \- (xml-apis:xml-apis:jar:1.4.01:compile - version managed from 1.3.04; omitted for duplicate)
|     +- org.apache.xmlgraphics:batik-svg-dom:jar:1.8:compile
|     |  +- (org.apache.xmlgraphics:batik-awt-util:jar:1.8:compile - omitted for duplicate)
|     |  +- (org.apache.xmlgraphics:batik-css:jar:1.8:compile - omitted for duplicate)
|     |  +- (org.apache.xmlgraphics:batik-dom:jar:1.8:compile - omitted for duplicate)
|     |  +- (org.apache.xmlgraphics:batik-ext:jar:1.8:compile - omitted for duplicate)
|     |  +- (org.apache.xmlgraphics:batik-parser:jar:1.8:compile - omitted for duplicate)
|     |  +- (org.apache.xmlgraphics:batik-util:jar:1.8:compile - omitted for duplicate)
|     |  +- (xml-apis:xml-apis:jar:1.4.01:compile - version managed from 1.3.04; omitted for duplicate)
|     |  \- (xml-apis:xml-apis-ext:jar:1.3.04:compile - omitted for duplicate)
|     +- org.apache.xmlgraphics:batik-util:jar:1.8:compile
|     +- org.apache.xmlgraphics:batik-xml:jar:1.8:compile
|     |  \- (org.apache.xmlgraphics:batik-util:jar:1.8:compile - omitted for duplicate)
|     +- (xml-apis:xml-apis:jar:1.4.01:compile - version managed from 1.3.04; omitted for duplicate)
|     \- xml-apis:xml-apis-ext:jar:1.3.04:compile
+- org.apache.poi:poi:jar:3.14:compile
|  \- commons-codec:commons-codec:jar:1.10:compile
\- org.apache.poi:poi-ooxml:jar:3.14:compile
   +- (org.apache.poi:poi:jar:3.14:compile - omitted for duplicate)
   +- org.apache.poi:poi-ooxml-schemas:jar:3.14:compile
   |  \- org.apache.xmlbeans:xmlbeans:jar:2.6.0:compile
   |     \- stax:stax-api:jar:1.0.1:compile
   \- com.github.virtuald:curvesapi:jar:1.03:compile

1 回答

  • 4

    我终于设法解决了这个问题 . 造成这种情况的原因是我为每个CassandraIterable实例重新实例化MappingCassandraConverter .

    public class CassandraIterable<T> implements Iterable<T> {
    
        private final Iterator<Row> iterator;
        private final Class<T> entityType;
    
        private final MappingCassandraConverter converter = new MappingCassandraConverter ();
    
        ...
    
    }
    

    虽然我应该创建它一次并将其传递给Iterable:

    public class CassandraIterable<T> implements Iterable<T> {
    
    
        private final Iterator<Row> iterator;
        private final Class<T> entityType;
    
        private final MappingCassandraConverter converter;
    
        public CassandraIterable(Iterator<Row> iterator, Class<T> entityType, MappingCassandraConverter converter) {
    
            this.iterator = iterator;
            this.entityType = entityType;
            this.converter = converter;
        }
    
        @Override
        public Iterator<T> iterator() {
            return
                    new Iterator<T>() {
                        @Override
                        public boolean hasNext() {
                            return
                                    iterator.hasNext();
                        }
    
                        @Override
                        public T next() {
                            return
                                    converter.readRow(entityType, iterator.next());
                        }
                    };
        }
    }
    

    MappingCassandraConverter不是垃圾收集的(我假设Cassandra会话指向它)并且我的类的访问器可能是由转换器指向的 .

    我找不到泄漏的原因是泄漏中没有特定的类型:

    enter image description here
    由于泄漏,我期待看到我的一个类型在内存中重复了数百万次 . 之所以没有发生这样的事实是我的代码中的问题是为Cassandra实体创建了很多访问器,即使只有一个类类型要生成 . 出于这个原因,涉及泄漏的类是这样的:

    enter image description here

    并且它们不在列表的顶部,按类型按总大小排序 .

相关问题