2013-03-05 81 views
0

我没有找出此错误的原因 “我的netty服务器在以下异常后没有处理任何消息。”Netty服务器接受连接并且什么都不做

org.jboss.netty.channel.SimpleChannelHandler - EXCEPTION, please implement com.kakapo.unity.handler.RegistrationHandler.exceptionCaught() for proper handling. 
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 223,384,284 milliseconds ago. The last packet sent successfully to the server was 223,384,284 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem. 
    at sun.reflect.GeneratedConstructorAccessor13.newInstance(Unknown Source) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525) 
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) 
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116) 
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3364) 
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1983) 
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163) 
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624) 
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127) 
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2293) 
    at snaq.db.CachedPreparedStatement.executeQuery(CachedPreparedStatement.java:81) 
    at com.kakapo.unity.handler.CustomIPFilterHandler.accept(CustomIPFilterHandler.java:46) 
    at org.jboss.netty.handler.ipfilter.IpFilteringHandlerImpl.handleUpstream(IpFilteringHandlerImpl.java:118) 
    at org.jboss.netty.handler.logging.LoggingHandler.handleUpstream(LoggingHandler.java:333) 
    at org.jboss.netty.channel.Channels.fireChannelConnected(Channels.java:227) 
    at org.jboss.netty.channel.socket.nio.NioWorker$RegisterTask.run(NioWorker.java:187) 
    at org.jboss.netty.channel.socket.nio.AbstractNioWorker.processRegisterTaskQueue(AbstractNioWorker.java:430) 
    at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:329) 
    at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:35) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) 
    at java.lang.Thread.run(Thread.java:722) 
Caused by: java.net.SocketException: Connection timed out 
    at java.net.SocketOutputStream.socketWrite0(Native Method) 
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109) 
    at java.net.SocketOutputStream.write(SocketOutputStream.java:153) 
    at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) 
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140) 
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3345) 
    ... 17 more 

但我已经把我的JDBC的auto reconnect = true。也正在使用OrderedMemoryAwareThreadPoolExecutor

ExecutionHandler channelExecutionHandler = new ExecutionHandler(new OrderedMemoryAwareThreadPoolExecutor(Runtime.getRuntime() 
       .availableProcessors(), 0, 0)); 

我使用awaituninteruptable函数来关闭通道。 like

ctx.getChannel().write(new ErrMessage(e.getChannel().getRemoteAddress().toString()).getEncodedMessage()) 

这是否导致任何类型的无限循环活动。 现在的情况是服务器接受连接,不处理任何类型的消息。我们有工作线程和老板。但日志处理程序工作正常。 正在使用snaq.db.connection池来维护数据库连接。

回答

1

你似乎使用MySQL连接非常简单,与DriverManager.getConnection()。因此,根本不要关闭打开的连接,或者创建如此多的连接,以至于超过MySQL服务器的限制。

在高度并发的环境中(Netty当然是为此而实现的)我强烈建议使用数据库连接池:c3p0commons-dbcp。通过适当的设置,您可以避免MySQL连接问题。

+0

感谢您的回答,但我已经使用数据库连接池“snaq.db.connection池”。 – 2013-03-05 10:34:33

+0

那么你能否告诉我们究竟连接池正在使用什么,也可能需要调整它的设置。 – n1ckolas 2013-03-05 10:39:00

+0

snaq.db.ConnectionPool objConnectionPool =新连接池( “DBPool对”(调用Runtime.getRuntime()。availableProcessors())* 6, \t \t \t \t \t(调用Runtime.getRuntime()。availableProcessors())* 6,( (调用Runtime.getRuntime()。availableProcessors())* 6) \t \t \t \t \t \t \t +(((调用Runtime.getRuntime()。availableProcessors())* 6)/ 2),0,mysqlString,用户,密码); – 2013-03-05 11:03:46

相关问题