Java应用程序

时间:2018-05-18 09:19:13

标签: java memory-leaks vert.x

我们正在一个Java应用程序中使用vert.x toolkit(用于在JVM上构建反应式应用程序)。过去几天我们已经开始看到高内存(堆)使用,有时会导致应用程序无响应(由于GC CPU周期使用量很大)。因此,为了研究吃堆内存的情况,我使用了Eclipse MAT工具来查找内存泄漏。这就是它所显示的:

enter image description here

不确定代码中究竟出了什么问题,所以需要专家建议。请在下面找到我的pom和顶点代码。如果您需要其他详细信息,请告诉我。我正在按照本指南vertex.io guide& vert.x java code e.g

的pom.xml

        <groupId>io.vertx</groupId>
        <artifactId>vertx-core</artifactId>
        <version>3.3.3</version>

使用io.vertex请求处理程序代码:

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import io.vertx.core.Vertx;
import io.vertx.core.WorkerExecutor; 

public class Processor {

private static final Map<String, WorkerExecutor> executorMap = new ConcurrentHashMap<>();

public WorkerExecutor getWorkerExecutor(String threadName, Vertx vertxObj) {
    WorkerExecutor executor = executorMap.get(threadName);
    if (executor == null) {
        synchronized (Processors.class) {
            executor = executorMap.get(threadName);
            if(executor == null){
                executor = vertxObj.createSharedWorkerExecutor(threadName);
                executorMap.putIfAbsent(threadName, executor);
            }
        }
    }
    return executor;
}

@POST
@Path("/update_record")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON })
public void processUpdateEvent(String data, @Suspended final AsyncResponse asyncResponse, @Context Vertx vertx) throws Exception{
    logger.info("update called");
    WorkerExecutor executor = getWorkerExecutor("update_record_event", vertx);
    executor.executeBlocking(future -> {
        MyProcessor processor = (MyProcessor) MainClass.context.getBean("myprocessorevent");
        try {
            processor.processMessage(data);
            future.complete();
        } catch (Exception e) {
            logger.error("consuming event failed: " + e.getMessage());
            future.fail(e);
        }
    }, res -> {
        Response response  = null;
        if(res.succeeded()) {
            response = Response.status(Response.Status.OK).build();
        } else {
            response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
        }
        asyncResponse.resume(response);
    });
  }
}

1 个答案:

答案 0 :(得分:0)

现在已经解决了!

  

实际上3.5.2.CR2之前所有版本都有内存泄漏;   有关更多信息,请查看此问题:   https://github.com/eclipse/vert.x/issues/2464fixed commit id

很快vert.x将公开发布其3.5.2版本。感谢vert.x community