(boolean mayInterruptIfRunning)
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public boolean cancel(boolean mayInterruptIfRunning) { |
| 95 | if (currentState.compareAndSet(State.New, State.Canceled)) { |
| 96 | handleDone(); |
| 97 | |
| 98 | return true; |
| 99 | } else if (mayInterruptIfRunning && |
| 100 | currentState.compareAndSet(State.Running, State.Canceling)) { |
| 101 | // handleDone will be called from running thread |
| 102 | try { |
| 103 | Thread runningThread = this.runningThread; |
| 104 | if (runningThread != null) { |
| 105 | runningThread.interrupt(); |
| 106 | |
| 107 | return true; |
| 108 | } |
| 109 | } finally { |
| 110 | // we can not set to canceled until interrupt status has been set |
| 111 | currentState.set(State.Canceled); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | return false; |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public boolean isCancelled() { |
nothing calls this directly
no test coverage detected