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

    Server push with Javamail: idle() blocks


      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() {
                     public void messagesAdded(MessageCountEvent arg0) {
                          DebugPrinter.print(this, "messagesAdded event called");
                          clear(false, true); // Clear cache
                     public void messagesRemoved(MessageCountEvent arg0) {
                          DebugPrinter.print(this, "messagesRemoved event called");
                          clear(false, true); // Clear cache
                MyThread thread = new MyThread() {
                     public void run() {
                          while (true) {
                               DebugPrinter.print(this, "Before idle");
                               try {
                                    DebugPrinter.print(this, "After idle");
                               } catch (MessagingException e) {
                                    // TODO Auto-generated catch block
                               DebugPrinter.print(this, "After idle try");
                // Start 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