java 连接超时 异常处理_java-CommunicationException [根本异常是ConnectException:连接超时]...

尝试连接Active Directory时,偶尔会遇到此异常.

javax.naming.CommunicationException: :

[Root exception is java.net.ConnectException: Connection timed out: connect]

这是我的代码:

DirContext ctx = null;

Properties env = new Properties();

env.put(Context.SECURITY_PRINCIPAL, );

env.put(Context.SECURITY_CREDENTIALS, );

env.put(Context.PROVIDER_URL, "ldap://:");

env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");

ctx = new InitialDirContext(env);

在此行中获取连接超时异常ctx = new InitialDirContext(env);.

它并非每次都发生,但经常发生.

请告诉我,如何摆脱这个问题?

解决方法:

我偶尔也会发生这种情况.而且由于它只发生约1%的时间,因此我怀疑这是Juned答案中列出的任何原因,因为我的设置没有任何变化.

对我来说,它是随机发生的,并且是固定的,不需要我做任何特定的动作.这使我相信here提供的答案是正确的:

It is most likely a connection leak. Connection timeout can be caused by many things but most of them would cause it every time. Very likely the LDAP server has a maximum number of connections it will handle simultaneously, and beyond that it won’t call accept(), so new incoming connections remain in the backlog queue, which fills up, which can cause further incoming connections to time out.

@OP Can you run netstat -anp at the server when this happens, to check the hypothesis above? Can you also set a connection-idle timeout at the LDAP server? That would fix connection leaks but in a brute-force way that may break other things.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值