有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何提高neo4jjdbcdriver的性能?

如何提高neo4j jdbc驱动程序的性能?我使用MVC结构来实现我的代码。构建ApacheHTTP客户端似乎需要3~5秒,所以我认为最好的方法是减少HTTP连接。但是为什么下面的代码会三次“启动Apache HTTP客户端”?,我想我只建立一次http连接

控制台日志

Starting the Apache HTTP client
Starting the Apache HTTP client
->Columns: [node] current row -1: null
Starting the Apache HTTP client
Stopping the HTTP client

新4J服务酯。java

@Test
public void findNodeTester() {
    try {
        String UUID = "306C0F88-0A26-41EA-A954-DFC7025402DC";
        neo4jService.findNode(UUID);
    } catch(Exception e) {
        e.printStackTrace();
    }
}

Neo4jService。java

public void findNode(String UUID) throws Exception {
    Neo4jConnection connection = new Driver().connect("jdbc:neo4j://172.11.13.23:7474?debug=true", new Properties());
    connection.setAutoCommit(false);
    NodeBean node;
    try {
        node = neo4jDAO.findNode(connection, UUID);
        System.out.println("node=" + node.toString());
        connection.commit();
    } catch(Exception e) {
        connection.rollback();
        e.printStackTrace();
    }
    connection.close(); 
}

BaseNeo4jDAO。java

public NodeBean findNode(Neo4jConnection connection, String UUID) throws Exception {
    String queryStr = "MATCH (n) WHERE n.UUID = \"" + UUID + "\" RETURN { id : ID(n), labels : labels(n), properties: n } as node";
    Statement stmt = connection.createStatement();
    ResultSet rs = stmt.executeQuery(queryStr); 
    rs.next();
    NodeBean node = new NodeBean();
    BeanUtils.populate(node, (Map<String, Object>) rs.getObject("node"));
    return node;
}

更新:

它似乎在以下情况下打印“启动Apache HTTP客户端”:

1. Neo4jConnection connection = neo4jDB.getConnection();
2. ResultSet rs = stmt.executeQuery(queryStr);
3. connection.commit();

共 (1) 个答案

  1. # 1 楼答案

    在你的程序中只做一次,然后把连接传进去

    Neo4jConnection connection = new Driver().connect("jdbc:neo4j://172.11.13.23:7474?debug=true", new Properties());
    connection.setAutoCommit(false);