我从头开始启动服务器,然后在某个 IP 和端口上应用程序(没有重复的服务器或端口已经使用)。由于 java-lang-OutOfMemory 错误,应用程序崩溃,说无法创建新线程。我分配了 JVM 4G 内存,现在该错误已消失。但是,现在启动客户端后又崩溃了。它运行了大约 10-15 秒,并因 SocketTimeoutException 而崩溃。这是痕迹
org.h2.jdbc.JdbcSQLException: Connection is broken: "java.net.SocketTimeoutException: connect timed out: MYIPADDRESS" [90067-172]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
at org.h2.message.DbException.get(DbException.java:158)
at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:407)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:295)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:105)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:90)
at org.h2.Driver.connect(Driver.java:73)
at java.sql.DriverManager.getConnection(DriverManager.java:579)
at java.sql.DriverManager.getConnection(DriverManager.java:221)
at com.org.tseries.simulator.IPEmailSeriesTestDriver.shootH2(IPEmailSeriesTestDriver.java:201)
at com.org.tseries.simulator.IPEmailSeriesTestDriver.processSimulator(IPEmailSeriesTestDriver.java:160)
at com.org.tseries.simulator.IPEmailSeriesTestDriver.main(IPEmailSeriesTestDriver.java:98)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at org.h2.util.NetUtils.createSocket(NetUtils.java:119)
at org.h2.util.NetUtils.createSocket(NetUtils.java:100)
at org.h2.engine.SessionRemote.initTransfer(SessionRemote.java:95)
at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:403)
... 14 more
当我从终端运行客户端时它崩溃了,但是当我从 STS(基于 Eclipse 的 IDE)运行相同的客户端时,它没有崩溃。运行客户端时我需要添加任何设置或标志吗?
更新:通过在连接字符串中附加 AUTORECONNECT=TRUE 来解决。更多详细信息,h2database.com/html/features.html#auto_reconnect
但现在,我有兴趣在服务器端建立一个连接池,允许不同的 TCP 客户端连接。服务器应为连接池中的客户端提供服务,而不是客户端再次重新连接。如何实现?