Uploaded image for project: 'JGroups'
  1. JGroups
  2. JGRP-2921

Runner: stop function is called in the wrong place

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 5.5.0
    • None
    • None
    • False
    • Hide

      None

      Show
      None
    • False

      Runner calls the stop function after terminating the loop:

          public void run() {
              for(;;) {
                  while(state == State.running) {
                      try {
                          function.run(); // e.g. ServerSocket.accept(), won't react to thread interruption!
                      }
                      catch(Throwable t) {
                      }
                  }
                  synchronized(this) {
                      switch(state) {
                          case stopped:
                          case stopping:
                              if(state == State.stopping) {
                                  runStopFuntion();
                                  state(State.stopped);
                              }
                              return;
                      }
                  }
              }
          }
      

      Runner.stop() interrupts the thread and relies on run() to execute the stop function. However, this does not work in some cases, e.g. ServerSocket.accept() does not react to interrupts, the the stop function of the runner will not be executed.

      Fix: move the calling of the stop function to Runner.stop(), after interrupting the thread:

         public synchronized Runner stop() {
              boolean rc=state(State.stopping);
              if(!rc)
                  return this;
              Thread tmp=thread;
              if(tmp != null) {
                  tmp.interrupt();
                  if(join_timeout > 0) {
                      try {tmp.join(join_timeout);} catch(InterruptedException e) {}
                  }
              }
              synchronized(this) {
                  switch(state) {
                      case stopped:
                      case stopping:
                          if(state == State.stopping) {
                              runStopFuntion();
                              state(State.stopped);
                          }
                  }
              }
              return this;
          }
      

              rhn-engineering-bban Bela Ban
              rhn-engineering-bban Bela Ban
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: