dcsimg
JavaMail API giving SocketTimeoutException intermittently
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Nitin_Tomer
Posted On:   Wednesday, June 30, 2010 06:45 AM

Problem Statement: I have created a utility(using JavaMail API) which downloads mails from the Exchange Server 2003(MS Windows server 2003) using IMAP service. The utility uses 5 different threads(each creating it's own separate IMAP session) to download the mails from the same user mailbox account. A separate main controlling thread has been used, which feeds these 5 threads with the start-end message counts with a batching of 100 messages. The 5 threads also set the message delete flag after downloading/processing the messages. And finally the main controlling thread expunges the mail box account after a certain amount of time(1 hour). (The service also takes care of expunging the messages at the startup as well.) The utility run   More>>

Problem Statement:

I have created a utility(using JavaMail API) which downloads mails from the Exchange Server 2003(MS Windows server 2003) using IMAP service.
The utility uses 5 different threads(each creating it's own separate IMAP session) to download the mails from the same user mailbox account. A separate main controlling thread has been used, which feeds these 5 threads with the start-end message counts with a batching of 100 messages. The 5 threads also set the message delete flag after downloading/processing the messages. And finally the main controlling thread expunges the mail box account after a certain amount of time(1 hour). (The service also takes care of expunging the messages at the startup as well.)

The utility runs fine for a long time(say 8 to 10 hours) but then it suddenly starts giving socket timeout exceptions and then it continues giving the exceptions. I even introduced a delay of 15 min. and increased the socket timeout period but to no avail. All i had to do was to restart the exchange server and after some time, i again started the utility and it worked finely.

Exception stack trace:

* BYE JavaMail Exception: java.net.SocketTimeoutException: Read timed out
javax.mail.MessagingException: * BYE JavaMail Exception: java.net.SocketTimeoutException: Read timed out;
nested exception is:
com.sun.mail.iap.ConnectionException: * BYE JavaMail Exception: java.net.SocketTimeoutException: Read timed out
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:477)
at javax.mail.Service.connect(Service.java:275)
at com.newgen.omni.mail.mswrapper.MailServerWrapper.connect(MailServerWrapper.java:102)
at com.newgen.omni.mail.mswrapper.MailServerWrapper. (MailServerWrapper.java:33)
at com.newgen.omni.mail.scheduler.Scheduler.Process(Scheduler.java:352)
at com.newgen.omni.mail.scheduler.Scheduler.run(Scheduler.java:293)
at com.newgen.omni.mail.scheduler.Scheduler.execute(Scheduler.java:1026)
at org.quartz.core.JobRunShell.run(JobRunShell.java:178)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:477)
Caused by: com.sun.mail.iap.ConnectionException: * BYE JavaMail Exception: java.net.SocketTimeoutException: Read timed out
at com.sun.mail.iap.Protocol.handleResult(Protocol.java:299)
at com.sun.mail.iap.Protocol.simpleCommand(Protocol.java:316)
at com.sun.mail.imap.protocol.IMAPProtocol.login(IMAPProtocol.java:290)
at com.sun.mail.imap.IMAPStore.login(IMAPStore.java:517)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:458)
... 8 more


The code snippet to make the IMAP connection (all the 6 threads call it separately to create separate sessions):

Properties prop = new Properties();
logger.debugMsg("mailCapture :: Process :: Initializing IMAP context...");
prop.put("mail.imap.appendbuffersize","-1");
prop.put("mail.imap.allowreadonlyselect","true");
prop.put("mail.imap.separatestoreconnection","true");
prop.put("mail.imap.partialfetch","false");
prop.put("mail.imap.connectiontimeout", "1200000");
prop.put("mail.imap.timeout", "1200000");

session = Session.getInstance(prop);
//session.setDebug(true);
logger.debugMsg("mailCapture :: Process :: Get Store...");
store = session.getStore("imap");
try
{
store.connect(mailServerInfo.strServerIP, Integer.parseInt(mailServerInfo.strServerPort), mailServerInfo.strUsername, mailServerInfo.strPassword);
}
catch(MessagingException ex)
{
logger.logException(ex.getMessage(), ex);
Thread.sleep(900000);
throw ex;
}

Please tell me what can be the possible cause and how to rectify it?

Regards

Nitin

   <<Less
About | Sitemap | Contact