我啓動了服務器,然後從頭開始在某個IP和端口上應用程序(沒有使用過度的服務器或端口)。由於java-lang-OutOfMemory錯誤,應用程序崩潰,說沒有新線程可以創建。我分配了JVM 4G內存,現在該錯誤是無聲的。但是,現在開始客戶端再次崩潰。它運行大約10-15秒,並與SocketTimeoutException崩潰。下面是跟蹤H2數據庫(服務器)TCP連接超時和連接池
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客戶端連接的連接池。服務器應爲連接池中的客戶端提供服務,而不是客戶端重新連接。如何實現?