转载

Mina No buffer space available (maximum connections reached?)

一、问题日志
2014-01-08 09:35:20 ERROR ErrorLogger:2015 - Job (DEFAULT.autoSend threw an exception. org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: org.springframework.scheduling.quartz.JobMethodInvocationFailedException: Invocation of method 'sendFile' on target class [class com.sun.proxy.$Proxy10] failed; nested exception is org.apache.mina.core.RuntimeIoException: Failed to create a new instance of org.apache.mina.transport.socket.nio.NioProcessor:null] at org.quartz.core.JobRunShell.run(JobRunShell.java:214) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) at java.lang.Thread.run(Thread.java:662) * Nested Exception (Underlying Cause) --------------- org.springframework.scheduling.quartz.JobMethodInvocationFailedException: Invocation of method 'sendFile' on target class [class com.sun.proxy.$Proxy10] failed; nested exception is org.apache.mina.core.RuntimeIoException: Failed to create a new instance of org.apache.mina.transport.socket.nio.NioProcessor:null at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:320) at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:113) at org.quartz.core.JobRunShell.run(JobRunShell.java:203) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) at java.lang.Thread.run(Thread.java:662) Caused by: org.apache.mina.core.RuntimeIoException: Failed to create a new instance of org.apache.mina.transport.socket.nio.NioProcessor:null at org.apache.mina.core.service.SimpleIoProcessorPool.(SimpleIoProcessorPool.java:200) at org.apache.mina.core.service.SimpleIoProcessorPool.(SimpleIoProcessorPool.java:114) at org.apache.mina.core.polling.AbstractPollingIoConnector.(AbstractPollingIoConnector.java:95) at org.apache.mina.transport.socket.nio.NioSocketConnector.(NioSocketConnector.java:55) at com.amssy.comm.client.Client.sendFile(Client.java:39) at com.amssy.datapush.service.impl.SendFileServiceImpl.sendFile(SendFileServiceImpl.java:76) at sun.reflect.GeneratedMethodAccessor54.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at com.sun.proxy.$Proxy10.sendFile(Unknown Source) at sun.reflect.GeneratedMethodAccessor52.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:273) at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:311) ... 5 more Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.GeneratedConstructorAccessor21.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at org.apache.mina.core.service.SimpleIoProcessorPool.(SimpleIoProcessorPool.java:182) ... 25 more Caused by: org.apache.mina.core.RuntimeIoException: Failed to open a selector. at org.apache.mina.transport.socket.nio.NioProcessor.(NioProcessor.java:61) ... 29 more Caused by: java.io.IOException: Unable to establish loopback connection at sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:106) at java.security.AccessController.doPrivileged(Native Method) at sun.nio.ch.PipeImpl.(PipeImpl.java:122) at sun.nio.ch.SelectorProviderImpl.openPipe(SelectorProviderImpl.java:27) at java.nio.channels.Pipe.open(Pipe.java:133) at sun.nio.ch.WindowsSelectorImpl.(WindowsSelectorImpl.java:104) at sun.nio.ch.WindowsSelectorProvider.openSelector(WindowsSelectorProvider.java:26) at java.nio.channels.Selector.open(Selector.java:209) at org.apache.mina.transport.socket.nio.NioProcessor.(NioProcessor.java:59) ... 29 more Caused by: java.net.SocketException: No buffer space available (maximum connections reached?): bind at sun.nio.ch.Net.bind(Native Method) at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:124) at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59) at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:52) at sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:72) ... 37 more one client sessionIdle:/192.168.53.106:9123::sessionIdle ::true
2、解决方法 windows查看连接数:
1
>netstat -ano -p tcp|findstr 9123
分析原因:太多的连接数导致的 修改代码: 自定义 IoHandlerAdapter 中需要有以下代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
        session.close(true);//force close right now
}
public void sessionOpened(IoSession session) throws Exception {
    session.getConfig().setBothIdleTime(180);//set timeout seconds, must
}
public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
    session.close(true);//timeout now, close it
}
    /**
     * session创建
     */
    public void sessionCreated(IoSession session) throws Exception {
        super.sessionCreated(session);
        System.out.println("one client sessionOpened"
                + session.getRemoteAddress());
         SocketSessionConfig cfg = (SocketSessionConfig) session.getConfig();  
            cfg.setReceiveBufferSize(2 * 1024 * 1024);  
            cfg.setReadBufferSize(2 * 1024 * 1024);  
            cfg.setKeepAlive(true);  
            cfg.setSoLinger(0); //这个是根本解决问题的设置 
    }
  修改之后的效果(单个客户端,最多的时候只有2条链接)
正文到此结束
Loading...