Periodically check for condition with timeout
The process is the following:
Request to check for particular email message received is came. This email message should be added to the list of messages that are periodically che开发者_开发知识库cked for availability on mail server. Every 30 seconds another thread should search for messages from this list. If message is found it should be returned somehow to function that made request. If message isn't found during specified timeout period, exception should be thrown.Note: I think that it may be quiet costly to create new thread every time new message appears. So I want to search for all messages from the list in one thread periodically.
How / with help of which classes I can implement it? (Javamail part is ready)
Use a
java.util.concurrent.BlockingQueue
to receive the message because you can saypoll(long timeout, TimeUnit unit)
so the receiving thread doesn't use any CPU at all.To check the mails periodically, use a
java.util.Timer
"for repeated execution at regular intervals".
精彩评论