Spring LDAP连接池 - 使用MutablePoolingContextSource时文件句柄未关闭

时间:2013-12-18 11:26:46

标签: tomcat file-handling spring-ldap

使用spring ldap连接池时,我不断收到以下异常。无论如何都建立了LDAP连接,一切都工作正常,直到最后tomcat在超过文件句柄大小限制后挂起,因为显然套接字没有关闭。任何想法为什么会发生这个问题以及如何解决它?

谢谢你们, 艾玛

Spring异常:

121295 [Timer-2] INFO org.springframework.ldap.pool.validation.DefaultDi rContextValidator []- DirContext 'javax.naming.ldap.InitialLdapContext@5034d0fe' failed validation.
121295 [Timer-2] WARN org.springframework.ldap.pool.validation.DefaultDi rContextValidator []- DirContext 'javax.naming.ldap.InitialLdapContext@432d76f2' failed validation with an exception.
javax.naming.CommunicationException: Connection reset [Root exception is java.net.SocketException: Connection reset]; remaining name ''
    at com.sun.jndi.ldap.LdapCtx.doSearch(LdapCtx.java:20 03)
    at com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1 847)
    at com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:17 72)
    at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_sea rch(ComponentDirContext.java:386)
    at com.sun.jndi.toolkit.ctx.PartialCompositeDirContex t.search(PartialCompositeDirContext.java:356)
    at com.sun.jndi.toolkit.ctx.PartialCompositeDirContex t.search(PartialCompositeDirContext.java:339)
    at javax.naming.directory.InitialDirContext.search(In itialDirContext.java:267)
    at org.springframework.ldap.pool.validation.DefaultDi rContextValidator.validateDirContext(DefaultDirCon textValidator.java:165)
    at org.springframework.ldap.pool.factory.DirContextPo olableObjectFactory.validateObject(DirContextPoola bleObjectFactory.java:169)
    at org.apache.commons.pool.impl.GenericKeyedObjectPoo l.evict(GenericKeyedObjectPool.java:1897)
    at org.apache.commons.pool.impl.GenericKeyedObjectPoo l$Evictor.run(GenericKeyedObjectPool.java:2272)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream. java:189)
    at java.net.SocketInputStream.read(SocketInputStream. java:121)
    at java.io.BufferedInputStream.fill(BufferedInputStre am.java:235)
    at java.io.BufferedInputStream.read1(BufferedInputStr eam.java:275)
    at java.io.BufferedInputStream.read(BufferedInputStre am.java:334)
    at com.sun.jndi.ldap.Connection.run(Connection.java:8 49)
    at java.lang.Thread.run(Thread.java:724)   

Tomcat例外:

Dec 14, 2013 1:05:57 PM org.apache.tomcat.util.net.JIoEndpoint$Acceptor run
SEVERE: Socket accept failed
java.net.SocketException: Too many open files
    at java.net.PlainSocketImpl.socketAccept(Native Method)
    at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:398)
    at java.net.ServerSocket.implAccept(ServerSocket.java:530)
    at java.net.ServerSocket.accept(ServerSocket.java:498)
    at org.apache.tomcat.util.net.DefaultServerSocketFactory.acceptSocket(DefaultServerSocketFactory.java:60)
    at org.apache.tomcat.util.net.JIoEndpoint$Acceptor.run(JIoEndpoint.java:216)
    at java.lang.Thread.run(Thread.java:724)

这是ldap连接池配置:

<bean id="sdLdapTemplate" class="org.springframework.ldap.core.LdapTemplate">
    <property name="contextSource" ref="sdContextSource" />
    <!-- <property name="contextSource" ref="sdContextSourceTarget" /> -->
</bean>

<bean id="sdContextSource"
    class="org.springframework.ldap.transaction.compensating.manager.TransactionAwareContextSourceProxy">
    <constructor-arg ref="sdPooledContextSource" />
</bean>

<bean id="sdPooledContextSource"
    class="org.springframework.ldap.pool.factory.MutablePoolingContextSource">
    <property name="contextSource" ref="sdContextSourceTarget" />
    <property name="dirContextValidator" ref="dirContextValidator" />
    <property name="testOnBorrow" value="false" />
    <property name="testWhileIdle" value="true" />
    <property name="minIdle" value="3" />
    <property name="maxIdle" value="8" />
    <property name="maxActive" value="100" />
    <property name="maxTotal" value="100" />
    <property name="maxWait" value="100" />
    <property name="timeBetweenEvictionRunsMillis" value="60000" />
    <property name="minEvictableIdleTimeMillis" value="180000" />
</bean>

<bean id="sdContextSourceTarget" class="org.springframework.ldap.core.support.LdapContextSource">
    <property name="url" value="${sd.url}" />
    <property name="userDn" value="${sd.account}" />
    <property name="password" value="${sd.pwd}" />
    <property name="pooled" value="false" />
</bean>

<bean id="dirContextValidator"
    class="org.springframework.ldap.pool.validation.DefaultDirContextValidator">
</bean>

0 个答案:

没有答案