你cancel时带的参数是true还是false?

解决方案 »

  1.   

    volatile !volatile boolean isStopped = false;doInBackground() {  while (!isStopped) {
        // do your work.
      } cancel() {
       isStopped = true;
     }
    }
    Note the key point is : in multithread occasion, var may not be seen immediately by other thread when modified,
    but if decorated by volatile, and when there is only one thread do write(modify the var),  the other read thread
    can see it immediately.It is related to system cache.
      

  2.   

    BTW : AtomicBoolean, or synchronized can also solve the problem.