JavaMail: Keeping IMAPFolder.idle() alive

后端 未结 4 584
盖世英雄少女心
盖世英雄少女心 2020-12-13 11:07

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

4条回答
  •  甜味超标
    2020-12-13 11:22

    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();
    

提交回复
热议问题