I am making a program that needs to monitor a Gmail account for new messages, and in order to get them ASAP I am using JavaMail\'s idle feature. Here is a code snippet from
checking the message count every 5 minutes works for me:
new Thread()
{
@Override
public void run()
{
startTimer();
}
private void startTimer()
{
int seconds = 0;
while (true)
{
try
{
Thread.sleep(300000);
int c = folder.getMessageCount();
}
catch (InterruptedException ex)
{
}
catch (MessagingException me)
{
}
}
}
}.start();