Why is the JavaMail connection timeout too long
•
Java
In my application, I connect to the server to authenticate users This is the code:
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; }
I set the connection timeout to 1000 ms = 1s, but ignored it When I debug and set the wrong user name and password, I catch it
javax.mail.MessagingException: java.net.socketTimeoutException: Read timed out
Not after 1000 ms, but after 5000 * 60 ms = 5 minutes
What's wrong? How can I reduce my time?
Solution
You can also set socket I / O timeout When it connects but fails to read data from the server, it will continue to wait
prop.put("mail.smtp.timeout",1000);
A read timeout indicates that you are connected but cannot read data from the server
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码