0

如果 maxDepth 为 3 代码运行良好,如果 maxDepth = 4 此代码挂起@对 td.traverse(start) 的调用(~第 38 行)& 然后我得到:

线程“主”java.lang.OutOfMemoryError 中的异常:java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100) 处 java.util.Arrays.copyOf(Arrays.java:2882) 处的 Java 堆空间。 AbstractStringBuilder.append(AbstractStringBuilder.java:515) at java.lang.StringBuilder.append(StringBuilder.java:189) at com.sun.jersey.core.util.ReaderWriter.readFromAsString(ReaderWriter.java:172) at com.sun .jersey.core.util.ReaderWriter.readFromAsString(ReaderWriter.java:157) 在 com.sun.jersey.core.provider.AbstractMessageReaderWriterProvider.readFromAsString(AbstractMessageReaderWriterProvider.java:114) 在 com.sun.jersey.core.impl.provider .entity.StringProvider.readFrom(StringProvider.java:73) 在 com.sun.jersey.core.impl.provider.entity.StringProvider.readFrom(StringProvider.java:58) 在 com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:552) 在 com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:505) 在 org.neo4j.rest .graphdb.RequestResult.extractFrom(RequestResult.java:87) 在 org.neo4j.rest.graphdb.ExecutingRestRequest.post(ExecutingRestRequest.java:138) 在 org.neo4j.rest.graphdb.ExecutingRestAPI.traverse(ExecutingRestAPI.java:486 ) 在 org.neo4j.rest.graphdb.traversal.RestTraversal.traverse(RestTraversal.java:162) 在 com.tr.cmg.alloy 的 org.neo4j.rest.graphdb.RestAPIFacade.traverse(RestAPIFacade.java:202)。 dao.psd.RelationalPathSearchDAO.executeRelationalPathSearch(RelationalPathSearchDAO.java:38) 在 com.tr.cmg.alloy.dao.psd.RelationalPathSearchDAO.main(RelationalPathSearchDAO.java:115)java:552) 在 com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:505) 在 org.neo4j.rest.graphdb.RequestResult.extractFrom(RequestResult.java:87) 在 org.neo4j.rest .graphdb.ExecutingRestRequest.post(ExecutingRestRequest.java:138) 在 org.neo4j.rest.graphdb.ExecutingRestAPI.traverse(ExecutingRestAPI.java:486) 在 org.neo4j.rest.graphdb.RestAPIFacade.traverse(RestAPIFacade.java:202 ) 在 org.neo4j.rest.graphdb.traversal.RestTraversal.traverse(RestTraversal.java:162) 在 com.tr.cmg.alloy.dao.psd.RelationalPathSearchDAO.executeRelationalPathSearch(RelationalPathSearchDAO.java:38) 在 com.tr。 cmg.alloy.dao.psd.RelationalPathSearchDAO.main(RelationalPathSearchDAO.java:115)java:552) 在 com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:505) 在 org.neo4j.rest.graphdb.RequestResult.extractFrom(RequestResult.java:87) 在 org.neo4j.rest .graphdb.ExecutingRestRequest.post(ExecutingRestRequest.java:138) 在 org.neo4j.rest.graphdb.ExecutingRestAPI.traverse(ExecutingRestAPI.java:486) 在 org.neo4j.rest.graphdb.RestAPIFacade.traverse(RestAPIFacade.java:202 ) 在 org.neo4j.rest.graphdb.traversal.RestTraversal.traverse(RestTraversal.java:162) 在 com.tr.cmg.alloy.dao.psd.RelationalPathSearchDAO.executeRelationalPathSearch(RelationalPathSearchDAO.java:38) 在 com.tr。 cmg.alloy.dao.psd.RelationalPathSearchDAO.main(RelationalPathSearchDAO.java:115)extractFrom(RequestResult.java:87) at org.neo4j.rest.graphdb.ExecutingRestRequest.post(ExecutingRestRequest.java:138) at org.neo4j.rest.graphdb.ExecutingRestAPI.traverse(ExecutingRestAPI.java:486) at org.neo4j .rest.graphdb.RestAPIFacade.traverse(RestAPIFacade.java:202) 在 org.neo4j.rest.graphdb.traversal.RestTraversal.traverse(RestTraversal.java:162) 在 com.tr.cmg.alloy.dao.psd.RelationalPathSearchDAO .executeRelationalPathSearch(RelationalPathSearchDAO.java:38) 在 com.tr.cmg.alloy.dao.psd.RelationalPathSearchDAO.main(RelationalPathSearchDAO.java:115)extractFrom(RequestResult.java:87) at org.neo4j.rest.graphdb.ExecutingRestRequest.post(ExecutingRestRequest.java:138) at org.neo4j.rest.graphdb.ExecutingRestAPI.traverse(ExecutingRestAPI.java:486) at org.neo4j .rest.graphdb.RestAPIFacade.traverse(RestAPIFacade.java:202) 在 org.neo4j.rest.graphdb.traversal.RestTraversal.traverse(RestTraversal.java:162) 在 com.tr.cmg.alloy.dao.psd.RelationalPathSearchDAO .executeRelationalPathSearch(RelationalPathSearchDAO.java:38) 在 com.tr.cmg.alloy.dao.psd.RelationalPathSearchDAO.main(RelationalPathSearchDAO.java:115)202) 在 org.neo4j.rest.graphdb.traversal.RestTraversal.traverse(RestTraversal.java:162) 在 com.tr.cmg.alloy.dao.psd.RelationalPathSearchDAO.executeRelationalPathSearch(RelationalPathSearchDAO.java:38) 在 com.tr .cmg.alloy.dao.psd.RelationalPathSearchDAO.main(RelationalPathSearchDAO.java:115)202) 在 org.neo4j.rest.graphdb.traversal.RestTraversal.traverse(RestTraversal.java:162) 在 com.tr.cmg.alloy.dao.psd.RelationalPathSearchDAO.executeRelationalPathSearch(RelationalPathSearchDAO.java:38) 在 com.tr .cmg.alloy.dao.psd.RelationalPathSearchDAO.main(RelationalPathSearchDAO.java:115)

package com.tr.cmg.alloy.dao.psd;

import java.util.ArrayList;

import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Path;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.neo4j.rest.graphdb.index.RestIndex;
import org.neo4j.rest.graphdb.traversal.RestTraversalDescription;

import com.tr.cmg.alloy.aspects.audit.DaoTierAuditAspect;
import com.tr.cmg.alloy.dao.psd.relationship.RelationType;
import com.tr.cmg.alloy.dao.support.neo4j.Neo4jDaoSupport;
import com.tr.cmg.alloy.domain.psd.NodeType;
import com.tr.cmg.alloy.services.psd.rps.RelationalPathSearch;
import com.tr.cmg.alloy.services.psd.rps.RelationalPathSearchResult;

public class RelationalPathSearchDAO extends Neo4jDaoSupport{

public RelationalPathSearchResult executeRelationalPathSearch(
        RelationalPathSearch rps) {

    RestIndex<Node> personIndex = API.getIndex(NodeType.PERSON.name());

    Node start = personIndex.get("KEY", rps.getPerson1PermId()).getSingle();
    Node end = personIndex.get("KEY", rps.getPerson2PermId()).getSingle();

    Iterable<Node> nodes = null;
    Iterable<Relationship> relationships = null;

    if (start != null && end != null) {

        TraversalDescription td = createTraversalDescription(rps);
        nodes = null;
        relationships = null;
        for (Path position : td.traverse(start)) {

            // Log audit record info
            DaoTierAuditAspect
                    .storeSqlStatement("Relational Path Neo4j Query: "
                            + rps.getPerson1PermId() + " -> "
                            + rps.getPerson2PermId());
            DaoTierAuditAspect.storeSqlParameters("");

            System.out.println(position);

            if (position.endNode().equals(end)) {
                nodes = position.nodes();
                relationships = position.relationships();
                break;
            }
        }

        if(nodes == null) {
            ArrayList<Node> x = new ArrayList<Node>();
            x.add(start);
            x.add(end);
            nodes = x;
        }
    }

    return new RelationalPathSearchResult(nodes, relationships);

}

private TraversalDescription createTraversalDescription(RelationalPathSearch rps) {

    RestTraversalDescription rtd = (RestTraversalDescription) API.createTraversalDescription();
    rtd.maxDepth(4);

    return  rtd
            .depthFirst()
            .relationships(RelationType.IsDirector, Direction.BOTH)
            .relationships(RelationType.HasGraduatedFrom, Direction.BOTH)
            .relationships(RelationType.IsOfficer, Direction.BOTH)
            .relationships(RelationType.IsUnknownOfficerDirectorAt, Direction.BOTH)
            .relationships(RelationType.IsInsiderAt, Direction.BOTH)
            .relationships(RelationType.IsEquityAnalystAt, Direction.BOTH)
            .relationships(RelationType.IsMemberOrChairmanOf, Direction.BOTH)
            .relationships(RelationType.IsChiefInvestmentOfficerAt, Direction.BOTH)
            .relationships(RelationType.IsDirectorOfResearchAt, Direction.BOTH)
            .relationships(RelationType.IsPortfolioManagerAt, Direction.BOTH)
            .relationships(RelationType.IsTraderAt, Direction.BOTH)
            .relationships(RelationType.IsEconomistAt, Direction.BOTH)
            .relationships(RelationType.IsSalesProfessionalAt, Direction.BOTH)
            .relationships(RelationType.IsStrategistAt, Direction.BOTH)
            .relationships(RelationType.IsExecutiveOfficerAt, Direction.BOTH)
            .relationships(RelationType.IsShariahSupervisoryAt, Direction.BOTH)
            .relationships(RelationType.IsNonExecutiveAt, Direction.BOTH)
            .relationships(RelationType.IsVEExecutive, Direction.BOTH)
            .relationships(RelationType.IsProvidingResearchOn, Direction.BOTH)
            .relationships(RelationType.IsAnalystAt, Direction.BOTH)
            .relationships(RelationType.IsReuterMessengerUserAt, Direction.BOTH)
            .relationships(RelationType.IsProvidingAssetClassCoverageOn, Direction.BOTH)
            .relationships(RelationType.IsSpeakingLanguageOf, Direction.BOTH)
            .relationships(RelationType.IsProvidingGeographyCoverageOf, Direction.BOTH)
            .relationships(RelationType.IsUnknownSellSideBuySideAt, Direction.BOTH)
            .relationships(RelationType.IsUnknownInsiderAt, Direction.BOTH)
            .relationships(RelationType.IsUnknownResearchAnalystAt, Direction.BOTH)
            .relationships(RelationType.IsUnknownVEExecutiveAt, Direction.BOTH)
            .relationships(RelationType.IsUnknownReutersMessengerUserAt, Direction.BOTH)
            .relationships(RelationType.IsUnknownStreetEventsUserAt, Direction.BOTH);
}

public static void main(String[] args) {

    RelationalPathSearchDAO dao = new RelationalPathSearchDAO();

    RelationalPathSearch rps = new RelationalPathSearch();
    rps.setPerson1PermId("34414591164");
    rps.setPerson2PermId("34414710307");

    RelationalPathSearchResult result = dao.executeRelationalPathSearch(rps);
    result.toJSON();

}

}

4

4 回答 4

1

您需要增加 JVM最大堆内存大小

您当前的 JVM 内存设置是什么?

于 2013-01-08T20:00:16.873 回答
0

看起来您正在尝试查找两个节点之间的路径,对吧?如果您通过 REST API 使用 allPaths 或 allSimplePaths 算法,它会更快并且需要更少的内存,因为它是双向遍历。

不确定 RestGraphDatabase 是否支持它。无论哪种方式,您都可以查看http://docs.neo4j.org/chunked/stable/rest-api-graph-algos.html

于 2013-01-09T14:33:18.167 回答
0

解决了,采用的方法将整个数据库拉入 json 并通过网络执行应该在 db 内运行的操作。

已在此GitHub 问题中解决。

于 2013-01-09T14:35:11.540 回答
0

您可以使用“-XMX”参数增加堆空间的内存。你也可以参考这个...如何为java增加内存中的堆空间

于 2013-01-09T09:24:27.247 回答