我目前正在尝试使用JavaMail从IMAP服务器(Gmail和其他人)获取电子邮件.基本上,我的代码工作:我确实可以得到标题,正文内容等.我的问题如下:当处理IMAP服务器(没有SSL)时,处理消息基本上需要1-2ms.当我使用IMAPS服务器(因此使用SSL,例如Gmail)时,我的消息达到250米左右.我只测量处理消息的时间(不考虑连接,握手等).
我知道,因为这是SSL,所以数据是加密的.但是,解密的时间不应该那么重要,不是吗?
我已经尝试设置更高的ServerCacheSize值,更高的connectionpoolsize,但我的想法很严重.谁有人遇到这个问题?有人可能希望解决它吗?
我担心JavaMail API每次从IMAPS服务器获取邮件时都会使用不同的连接(涉及握手的开销......).如果是这样,有没有办法覆盖这种行为?
这是从Main()类调用的代码(虽然非常标准):
public static int connectTest(String SSL, String user, String pwd, String host) throws IOException,
ProtocolException,
GeneralSecurityException {
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", SSL);
props.setProperty("mail.imaps.ssl.trust", host);
props.setProperty("mail.imaps.connectionpoolsize", "10");
try {
Session session = Session.getDefaultInstance(props, null);
// session.setDebug(true);
Store store = session.getStore(SSL);
store.connect(host, user, pwd);
Folder inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_ONLY);
int numMess = inbox.getMessageCount();
Message[] messages = inbox.getMessages();
for (Message m : messages) {
m.getAllHeaders();
m.getContent();
}
inbox.close(false);
store.close();
return numMess;
} catch (MessagingException e) {
e.printStackTrace(); …Run Code Online (Sandbox Code Playgroud)