【问题标题】:Orientdb connection not closingOrientdb 连接未关闭
【发布时间】:2016-11-09 15:17:13
【问题描述】:

我正在使用 Orientdb 2.2.12

这是我获取连接实例

的单一来源
public static synchronized Connection getOrientDbConnection(String appName)
    {
        try {
            // address of Db Server
            OServerAdmin serverAdmin = new OServerAdmin
                    ("remote:" + ip + ":" + port + "/"
                            + appName).connect("root", "1234");

            if (serverAdmin.existsDatabase())
            {
                serverAdmin.close();
                Properties info = new Properties();
                info.put("user", "root");
                info.put("password", "1234");
                Connection conn = (OrientJdbcConnection) DriverManager.getConnection("jdbc:orient:remote:"  + ip + ":" + port + "/"
                        + appName, info);

                //System.out.println(" Database Connection  instance returned for : " + appName  + " for thread ID : " + Thread.currentThread().getId());

                return conn;
            }
            else
            {
                // "Type_Of_Db", "Type_Of_Storage"
                serverAdmin.createDatabase("GRAPH", "plocal");
                serverAdmin.close();

                OrientGraphFactory graphFactory = new OrientGraphFactory(
                        "remote:" + ip + ":" + port + "/" + appName);
                /**
                 * ####################### Do This only Ones-Per-Database #####################
                 * 1. Create index with unique field
                 *      @name = unique index will be created only one time for a particular database
                 *
                 *
                 */
                OrientGraphNoTx graph = graphFactory.getNoTx();
                graph.createKeyIndex("name", Vertex.class, new Parameter<String, String>("type", "UNIQUE"));

                // shutdown the graph which created Index immediately
                graph.commit();
                graph.shutdown();

                // close all db pools
                graphFactory.close();

                try 
                {
                    Properties info = new Properties();
                    info.put("user", "root");
                    info.put("password", "pcp");
                    Connection conn = (OrientJdbcConnection) DriverManager.getConnection("jdbc:orient:remote:" +ip + ":" + port + "/" + appName, info);

                    //System.out.println(" Database created and Connection instance return for : " + appName  + " for thread ID : " + Thread.currentThread().getId());

                    return conn;

                } catch (Exception e) {
                    //System.out.println("Problem creating database or getting connection from database "  + " for thread ID : " + Thread.currentThread().getId() + e.getMessage());
                    e.getMessage();
                    return null;
                }

            }
        }
        catch(Exception e)
        {
            e.getMessage();
        }
        return null;
    }

我的用例正在创建:-

  • 顶点
  • 边缘
  • 更新顶点、边等。

App.java

    Connection conn = DB.getOrientDbConnection(String appName)

    // create vertex
    // create edges

   conn.commit()
   conn.close();

我面临什么问题?

即使在程序完成并且conn.close() 完成后,显示 Orientdb 连接的 JConsole 仍然处于活动状态。

    Name: OrientDB <- Asynch Client (/192.168.1.11:4424)
    State: RUNNABLE
    Total blocked: 0  Total waited: 136

Stack trace: 
java.net.SocketInputStream.socketRead0(Native Method)
java.net.SocketInputStream.socketRead(Unknown Source)
java.net.SocketInputStream.read(Unknown Source)
java.net.SocketInputStream.read(Unknown Source)
java.io.BufferedInputStream.fill(Unknown Source)
java.io.BufferedInputStream.read(Unknown Source)
   - locked java.io.BufferedInputStream@1780dcd
java.io.DataInputStream.readByte(Unknown Source)
com.orientechnologies.orient.enterprise.channel.binary.OChannelBinary.readByte(OChannelBinary.java:68)
com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient.beginResponse(OChannelBinaryAsynchClient.java:189)
com.orientechnologies.orient.client.binary.OAsynchChannelServiceThread.execute(OAsynchChannelServiceThread.java:51)
com.orientechnologies.common.thread.OSoftThread.run(OSoftThread.java:77)

这是一个错误还是我做错了什么?

【问题讨论】:

    标签: orientdb graph-databases orientdb-2.1 orientdb2.2


    【解决方案1】:

    如果您的服务器正在运行,您将在 JConsole 中看到它。

    【讨论】:

    • 在一个 100 线程的系统上,一个有 100 个 Orientdb 未关闭的连接。这不会导致内存堆问题吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-18
    • 2016-06-09
    • 2016-08-07
    • 1970-01-01
    • 2012-08-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多