gpt4 book ai didi

java - CommunicationException [根异常是 ConnectException : Connection timed out]

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:52:31 24 4
gpt4 key购买 nike

我在尝试连接 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.

关于java - CommunicationException [根异常是 ConnectException : Connection timed out],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16412582/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com