Java 在neo4j jdbc中执行的密码查询被卡住而不返回结果集
} 我在线程内调用updateTopCallers()方法。此外,我同时使用大量线程来完成此任务。正如我所观察到的,当我使用Neo4jUtil类的单个实例时,就会发生这种情况(就像在单一设计模式中一样) 这是我的Neo4jUtil课程Java 在neo4j jdbc中执行的密码查询被卡住而不返回结果集,java,jdbc,neo4j,cypher,Java,Jdbc,Neo4j,Cypher,} 我在线程内调用updateTopCallers()方法。此外,我同时使用大量线程来完成此任务。正如我所观察到的,当我使用Neo4jUtil类的单个实例时,就会发生这种情况(就像在单一设计模式中一样) 这是我的Neo4jUtil课程 public void updateTopCallers(){ String queryString1 = "MATCH(a:Account) WHERE a.name='" + key + "' MATCH(p:Person)-[:USED_BY]->(a
public void updateTopCallers(){
String queryString1 = "MATCH(a:Account) WHERE a.name='" + key + "' MATCH(p:Person)-[:USED_BY]->(a) RETURN p.id as personId LIMIT 1";
try {
ResultSet resultSet = getQueryResult(queryString1);//in debugging, process didn't continue after this line.
if (resultSet.next()){
ownerId = resultSet.getString("personId");
System.out.println("ownerId:"+ownerId);
//In here also I'm executing few other cypher queries
//using same Neo4jUtil instance.
}
}catch (Exception e){
e.printStackTrace();
}
}
当我使用下面的方法来获取特定密码的结果集时,效果很好
public class Neo4jUtil {
private Neo4jConnection neo4jConnection = null;
private String restUrl = null;
private String driver = null;
private String userName = null;
private String passWord = null;
private static PropertiesUtility propertiesUtility = null;
private Neo4jUtil(){
try {
restUrl = getPropertiesCache().getCofigProperty("neo4j_url");
driver = getPropertiesCache().getCofigProperty("neo4j_driver");
userName = getPropertiesCache().getCofigProperty("neo4j_user");
passWord = getPropertiesCache().getCofigProperty("neo4j_pwd");
createDbConnection();
} catch (Exception e) {
e.printStackTrace();
}
}
private void createDbConnection(){
try {
Class.forName(driver);
neo4jConnection = (Neo4jConnection) DriverManager.getConnection(restUrl,userName,passWord);
System.out.println("neo4jConnection:"+neo4jConnection.toString());
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
private static PropertiesUtility getPropertiesCache() throws Exception {
if(propertiesUtility==null){
propertiesUtility = PropertiesUtility.getInstance();
return propertiesUtility;
}
else {
return propertiesUtility;
}
}
private static class Neo4jHolder{
private static final Neo4jUtil NEO4J_INSTANCE = new Neo4jUtil();
}
public static Neo4jUtil getInstance() {
return Neo4jHolder.NEO4J_INSTANCE;
}
// Querying
public ResultSet getQueryResult(String queryString){
try{
Neo4jStatement stmt = (Neo4jStatement) neo4jConnection.createStatement();
ResultSet rs = stmt.executeQuery(queryString);
return rs;
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
我正在使用Neo4jJDBC2.3.2作为我的Neo4jJava客户端 我有两种可能 首先,这个
private ResultSet executeCypher(String queryString){
try {
String restUrl = getPropertiesCache().getCofigProperty("neo4j_url");
String driver = getPropertiesCache().getCofigProperty("neo4j_driver");
String userName = getPropertiesCache().getCofigProperty("neo4j_user");
String passWord = getPropertiesCache().getCofigProperty("neo4j_pwd");
Class.forName(driver);
Neo4jConnection connection = (Neo4jConnection) DriverManager.getConnection(restUrl, userName, passWord);
Neo4jStatement stmt = (Neo4jStatement) connection.createStatement();
ResultSet rs = stmt.executeQuery(queryString);
stmt.close();
connection.close();
return rs;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
当我使用neo4j rest graphdb客户端时,它工作得很好。当我是线程的时候,我和那个客户端有问题。你说“卡住”是什么意思?你能简化代码吗?这个代码很乱,回答这个问题太难推理了。我从一个包含15000个密钥的redis db获得密钥。因为密钥是msisdn,所以至少应该有相似数量的人员。
final List<String> keyList = keyScanCursor.getKeys();
MATCH(person:Person)-[:USED_BY]->(a) RETURN person LIMIT 1"