简体   繁体   English

H2数据库(嵌入式)连接超时

[英]H2 Database (embedded) connection timeout

I get the following exception when connecting to the database: 连接到数据库时出现以下异常:

org.h2.jdbc.JdbcSQLException: Connection is broken: "connect timed out" [90067-142]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:327)
    at org.h2.message.DbException.get(DbException.java:156)
    at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:326)
    at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:248)
    at org.h2.engine.SessionRemote.createSession(SessionRemote.java:214)
    at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:111)
    at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:95)
    at org.h2.Driver.connect(Driver.java:73)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
................
Caused by: java.net.SocketTimeoutException: connect timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    at java.net.Socket.connect(Socket.java:525)
    at org.h2.util.NetUtils.createSocket(NetUtils.java:109)
    at org.h2.util.NetUtils.createSocket(NetUtils.java:91)
    at org.h2.engine.SessionRemote.initTransfer(SessionRemote.java:92)
    at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:322)
    ... 38 more

The connection string looks as follows: 连接字符串如下所示:

jdbc:h2:C:\Users\Michael\.myadd\db;AUTO_SERVER=TRUE;CIPHER=AES

What can be the reason for such exception? 发生这种异常的原因可能是什么?

Thanks! 谢谢!

For h2 default connection pool size is 10 and login timeout is 30 sec, if we acquire 10 simultaneous connection for longer period then new request to acquire connection will be timed out. 对于h2,默认连接池大小为10,登录超时为30秒,如果我们获取10个并发连接的时间更长,则新的获取连接的请求将超时。 for my case found that connection was not getting closed due to bug in code. 对于我的案例,发现由于代码错误,连接没有关闭。 we can increase max connection count. 我们可以增加最大连接数。

connectionPool.setMaxConnections(20);

but by default db manager is single threaded so more connection will not gain any performance. 但是默认情况下,数据库管理器是单线程的,因此更多的连接不会获得任何性能。

I guess you read the docs about the automatic mixed mode ? 我猜您阅读了有关自动混合模式文档 It's hard to say what the problem is, because for me it works. 很难说问题出在哪里,因为对我来说,它起作用了。 Could you post the content of the file C:\\Users\\Michael.myadd\\db.lock.db ? 您可以发布文件C:\\ Users \\ Michael.myadd \\ db.lock.db的内容吗? For me it is (after connecting): 对我来说(连接后):

#FileLock
#Tue Dec 14 22:29:22 CET 2010
id=12ce6c9a16a912077e514cc6fff231e91b09d2dbe43
method=file
server=192.168.0.126\:52068

That means the database is open, and the client that opened it started a server on this IP address and port. 这意味着数据库已打开,并且打开数据库的客户端在此IP地址和端口上启动了服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM