Reputation: 15973
What does make more sense for JavaMail?
Create a Store connection for each request to the email server and then close it immediately after the task has been completed.
Open a Store connection and only re-connect if the connection got closed by the server or the local application got terminated.
While (1) can lead to many connect() and close() calls in a row, (2) can block resources although that wouldn't be really necessary (but IMAP/POP3 calls would be fast since no extra .connect() call is required).
Upvotes: 4
Views: 1774
Reputation: 2651
Connect on Demand is better unless you have a requirement to poll the server frequently from a single thread.
Upvotes: 4