[ https://issues.apache.org/jira/browse/HARMONY-5933?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Tim Ellison closed HARMONY-5933. -------------------------------- Resolution: Invalid Please re-open if this is shown to be a problem in the Harmony code. > FutureTask.cancel() might not actaully cancel the task > ------------------------------------------------------ > > Key: HARMONY-5933 > URL: https://issues.apache.org/jira/browse/HARMONY-5933 > Project: Harmony > Issue Type: Bug > Components: Classlib > Affects Versions: 5.0M6 > Reporter: Jarek Gawor > > In some circumstances java.util.concurrent.FutureTask.cancel() might not actaully cancel the task. The problem is in innerCancel() method: > 1. boolean innerCancel(boolean mayInterruptIfRunning) { > 2. int s = getState(); > 3. if (ranOrCancelled(s) || !compareAndSetState(s, CANCELLED)) > 4. return false; > 5. > The issue is that the state (s) can change between line 2 and 3 and so compareAndSetState(s, CANCELLED) will return false and the cancel logic will not be performed (cancel() will return false but that task is not complete and it will continue to execute). This problem is more evident with periodic tasks where the state keep changing between 0 -> RUNNING, and RUNNING -> 0 (see innerRunAndReset()). > Looks like FutureTask implementation in Sun's JDK avoids this problem by adding a for (;;) loop around line 2 and 3: > for (;;) { > int s = getState(); > if (ranOrCancelled(s)) { > return false; > } > if (compareAndSetState(s, CANCELLED)) { > break; > } > } > -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.