ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

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

2019-11-23 09:10:46  阅读:918  来源: 互联网

标签:ldap runtime-error connectexception communicationexception java


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

javax.naming.CommunicationException: <ServerIP>:<PORT> 
  [Root exception is java.net.ConnectException: Connection timed out: connect]

这是我的代码:

    DirContext ctx = null;
    Properties env = new Properties();

    env.put(Context.SECURITY_PRINCIPAL, <Bind_USER>);
    env.put(Context.SECURITY_CREDENTIALS, <Bind_USER_PWD>);
    env.put(Context.PROVIDER_URL, "ldap://<ServerIP>:<PORT>");            
    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.

标签:ldap,runtime-error,connectexception,communicationexception,java
来源: https://codeday.me/bug/20191123/2066811.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有