我有一个java应用程序,它使用orientDB API(tinkerprop包)来创建Class并从OrientDB插入和提取数据。数据库正在另一台服务器上运行。动态连接到orientdb
我正在寻找我的应用程序,以防万一orientDB被关闭并且后来出现时,我不需要重新启动我的java应用程序来获得与orientDB的连接。 (数据库可用时连接应自动刷新)
我可能在复制设置中有2个节点,但在两个节点都需要重新启动的情况下,我的应用程序也需要重新启动。 (都面临着当插入没有发生因法定人数不可到达错误的情况下,最后,需要重新启动两台服务器)
我试着用下面的代码
while(true)
{
try {
OrientGraphFactory factory = new OrientGraphFactory("remote:localhost/testdb", "root", "root").setupPool(1,50);
OrientGraphNoTx graph = factory.getNoTx();
Thread.sleep(1*30*1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
但是当我关闭终止应用程序orientDB服务器。下面的异常被抛出,当服务器关闭
Exception in thread "main" com.orientechnologies.orient.core.exception.OStorageException: Cannot create a connection to remote server address(es): [127.0.0.1:2424]
DB name="testdb"
at com.orientechnologies.orient.client.remote.OStorageRemote.openRemoteDatabase(OStorageRemote.java:1960)
at com.orientechnologies.orient.client.remote.OStorageRemote.openRemoteDatabase(OStorageRemote.java:1860)
at com.orientechnologies.orient.client.remote.OStorageRemote.open(OStorageRemote.java:356)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.open(ODatabaseDocumentTx.java:258)
at com.orientechnologies.orient.core.db.OPartitionedDatabasePool$DatabaseDocumentTxPooled.internalOpen(OPartitionedDatabasePool.java:447)
at com.orientechnologies.orient.core.db.OPartitionedDatabasePool.openDatabase(OPartitionedDatabasePool.java:310)
at com.orientechnologies.orient.core.db.OPartitionedDatabasePool.acquire(OPartitionedDatabasePool.java:268)
at com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.<init>(OrientBaseGraph.java:143)
at com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx.<init>(OrientGraphNoTx.java:62)
at com.tinkerpop.blueprints.impls.orient.OrientGraphFactory$2.getGraph(OrientGraphFactory.java:116)
at com.tinkerpop.blueprints.impls.orient.OrientGraphFactory.getNoTx(OrientGraphFactory.java:240)
你就不能检查服务器的健康和实现循环重新连接以防万一? –
已经添加了代码给我的问题,我试图检查服务器的健康状态 – Ayush