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: Read timed out
javax.mail.MessagingException: * BYE JavaMail Exception: Read timed out;
nested exception is:
com.sun.mail.iap.ConnectionException: * BYE JavaMail Exception: Read timed out
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPSt
at javax.mail.Service.connect(
at com.newgen.omni.mail.mswrapper.MailServerWrapper.c onnect(
at com.newgen.omni.mail.mswrapper.MailServerWrapper.< init>(
at com.newgen.omni.mail.scheduler.Scheduler.Process(S
at com.newgen.omni.mail.scheduler.Scheduler.execute(S
at 78)
at org.quartz.simpl.SimpleThreadPool$ (
Caused by: com.sun.mail.iap.ConnectionException: * BYE JavaMail Exception: Read timed out
at com.sun.mail.iap.Protocol.handleResult(Protocol.ja va:299)
at com.sun.mail.iap.Protocol.simpleCommand(Protocol.j ava:316)
at com.sun.mail.imap.protocol.IMAPProtocol.login(IMAP
at com.sun.mail.imap.IMAPStore.login( 17)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPSt
... 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.separatestoreconnection","true ");
prop.put("mail.imap.connectiontimeout", "1200000");
prop.put("mail.imap.timeout", "1200000");

session = Session.getInstance(prop);
logger.debugMsg("mailCapture :: Process :: Get Store...");
store = session.getStore("imap");
store.connect(mailServerInfo.strServerIP, Integer.parseInt(mailServerInfo.strServerPort), mailServerInfo.strUsername, mailServerInfo.strPassword);
catch(MessagingException ex)
logger.logException(ex.getMessage(), ex);
throw ex;

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