JNDI を使用して LDAP に接続していますが、多数の同時 TCP 接続を処理する必要があります。すべての接続を同時に確立する必要があります。ミステリーは、それが機能することもあれば、30のうち17など、いくつかの接続のみを確立することもあります。グーグルで同様の問題を見ましたが、誰も解決策を提供しませんでした. ありがとう!スタックトレース:
javax.naming.ServiceUnavailableException: 172.16.0.xxx:389; socket closed
at com.sun.jndi.ldap.Connection.readReply(Connection.java:464)
at com.sun.jndi.ldap.LdapClient.ldapBind(LdapClient.java:370)
at com.sun.jndi.ldap.LdapClient.authenticate(LdapClient.java:222)
at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2752)
at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:328)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:205)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:223)
at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:166)
at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:96)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:695)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:318)
at javax.naming.InitialContext.init(InitialContext.java:253)
at javax.naming.InitialContext.<init>(InitialContext.java:227)
at javax.naming.directory.InitialDirContext.<init>(InitialDirContext.java:112)
編集:いくつかのコード
socket = new Socket(hostname, port);
is = socket.getInputStream();
os = socket.getOutputStream();
bif = new BufferedInputStream(is);
bof = new BufferedOutputStream(os);
env = new Hashtable<String, String>();
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, usr);
env.put(Context.SECURITY_CREDENTIALS, pwd);
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.REFERRAL,"follow");
env.put("java.naming.ldap.derefAliases", "never");
env.put(Context.PROVIDER_URL, "ldap:// /*address*/);
try {
ctx = new InitialDirContext(env);//ERROR
} catch (ServiceUnavailableException e1) {
e1.printStackTrace();
System.out.println("service unavailable");
}