1 2 Previous Next 16 Replies Latest reply: Dec 22, 2011 5:45 PM by 823071 RSS

    Server push with Javamail: idle() blocks

    823071
      Hi,

      today I tried to implement server push functionality in my mail application via Javamail.

      I did this by calling the following method everytime Javamail creates a new Folder instance for me:
      private void activateServerPush(Folder f) {
           if (f instanceof IMAPFolder) {
                final IMAPFolder ifo = (IMAPFolder) f;
                ifo.addMessageCountListener(new MessageCountListener() {
                     @Override
                     public void messagesAdded(MessageCountEvent arg0) {
                          DebugPrinter.print(this, "messagesAdded event called");
                          clear(false, true); // Clear cache
                          onMessageCountChanged();
                     }
      
                     @Override
                     public void messagesRemoved(MessageCountEvent arg0) {
                          DebugPrinter.print(this, "messagesRemoved event called");
                          clear(false, true); // Clear cache
                          onMessageCountChanged();
                     }
                });
      
                MyThread thread = new MyThread() {
                     @Override
                     public void run() {
                          while (true) {
                               DebugPrinter.print(this, "Before idle");
                               try {
                                    ifo.idle();
                                    DebugPrinter.print(this, "After idle");
                               } catch (MessagingException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                               }
                               DebugPrinter.print(this, "After idle try");
                          }
                     }
                };
      
                // Start thread
                ServletThread.EXECUTOR_SERVICE.submit(thread);
           }
      }
      Now, when I run the code above, I only get "Before idle" as output.
      The rest won't be printed so it seems like idle() is blocking.
      Also, the event listener messagesAdded(...) are not called. I tried this by sending an email to myself but nothing happens.

      What's wrong?
        1 2 Previous Next