开发者

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)


  1. Use a java.util.concurrent.BlockingQueue to receive the message because you can say poll(long timeout, TimeUnit unit) so the receiving thread doesn't use any CPU at all.

  2. To check the mails periodically, use a java.util.Timer "for repeated execution at regular intervals".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜