This change checks for isCancelled() inside the loop to be able to terminate the thread as early as possible.