为什么JavaMail连接超时太长
发布时间:2020-12-14 16:19:48 所属栏目:Java 来源:网络整理
导读:在我的应用程序中,我连接到服务器来验证用户.这是代码: try { Properties prop = new Properties(); prop.put("mail.smtp.starttls.enable","true"); prop.put("mail.smtp.auth","true"); prop.put("mail.smtp.connectiontimeout",1000); Session session =
在我的应用程序中,我连接到服务器来验证用户.这是代码:
try { Properties prop = new Properties(); prop.put("mail.smtp.starttls.enable","true"); prop.put("mail.smtp.auth","true"); prop.put("mail.smtp.connectiontimeout",1000); Session session = Session.getInstance(prop,null); Transport transport = session.getTransport("smtp"); transport.connect("mion.elka.pw.edu.pl",587,registerLog,registerPass); transport.close(); return true; } catch (NoSuchProviderException ex) { Logger.getLogger(RegisterController.class.getName()).log(Level.SEVERE,null,ex); return false; } catch(AuthenticationFailedException ex) { Logger.getLogger(RegisterController.class.getName()).log(Level.SEVERE,ex); return false; } catch (MessagingException ex) { Logger.getLogger(RegisterController.class.getName()).log(Level.SEVERE,ex); return false; } 我将连接超时设置为1000 ms = 1s,但忽略.当我调试并设置错误的用户名和密码我抓住 javax.mail.MessagingException: java.net.SocketTimeoutException: Read timed out 不是在1000 ms后,但在5000 * 60 ms = 5分钟后 哪里不对 ?我如何减少时间? 解决方法
您还可以设置Socket I / O超时.当连接但未能从服务器读取数据时,它将继续等待.
prop.put("mail.smtp.timeout",1000); 读取超时表示您已连接,但无法从服务器读取数据. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |