harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Beyer (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HARMONY-5933) FutureTask.cancel() might not actaully cancel the task
Date Wed, 06 Aug 2008 01:24:44 GMT

    [ https://issues.apache.org/jira/browse/HARMONY-5933?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12620112#action_12620112
] 

Nathan Beyer commented on HARMONY-5933:
---------------------------------------

Without knowing where you got the code snippet mentioned as "Sun's JDK", I need to mention
that you should avoid posting possibly copyrighted code. Most of the vendor's maintain copyright
of their source code, so please be careful with what you're reading, copying and pasting.

Aside from that, is the FutureTask you're looking at from the Java SE 5, main trunk, or from
the Java SE 6 branch. For the most part, we don't do development or maintenance on the code
directly, rather we get drops of code from Doug Lea's concurrency site [1]. I'd suggest checking
the code there and seeing what the state of this class is.

[1] http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/main/

> 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.            <cancel logic>
> 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;
>    }
> }
> <cancel logic>

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message