You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Henri Biestro (JIRA)" <ji...@apache.org> on 2016/07/14 07:33:20 UTC

[jira] [Comment Edited] (JEXL-205) testCancelForever() is not terminated properly

    [ https://issues.apache.org/jira/browse/JEXL-205?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15376493#comment-15376493 ] 

Henri Biestro edited comment on JEXL-205 at 7/14/16 7:32 AM:
-------------------------------------------------------------

This is the modification I made. Calling 'cancel' will call interrupt() on that running thread; this is the intended behavior.
{code}
        public int runForever() {
            while (true) {
                if (Thread.currentThread().isInterrupted()) {
                    break;
                }
            }
            return 1;
        }
{code}


was (Author: henrib):
This is the modification I made.
{code}
        public int runForever() {
            while (true) {
                if (Thread.currentThread().isInterrupted()) {
                    break;
                }
            }
            return 1;
        }
{code}

> testCancelForever() is not terminated properly
> ----------------------------------------------
>
>                 Key: JEXL-205
>                 URL: https://issues.apache.org/jira/browse/JEXL-205
>             Project: Commons JEXL
>          Issue Type: Task
>    Affects Versions: 3.0
>            Reporter: Dmitri Blinov
>
> After runnning Jexl tests I have noticed that the thread from testCancelForever() test is still executing, and its stack trace is as follows:
> {code}
> org.apache.commons.jexl3.ScriptCallableTest$TestContext.runForever(ScriptCallableTest.java:159)
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> java.lang.reflect.Method.invoke(Method.java:606)
> org.apache.commons.jexl3.internal.introspection.MethodExecutor.invoke(MethodExecutor.java:93)
> org.apache.commons.jexl3.internal.Interpreter.call(Interpreter.java:1816)
> org.apache.commons.jexl3.internal.Interpreter.visit(Interpreter.java:1535)
> org.apache.commons.jexl3.parser.ASTFunctionNode.jjtAccept(ASTFunctionNode.java:18)
> org.apache.commons.jexl3.internal.Interpreter.visit(Interpreter.java:1119)
> org.apache.commons.jexl3.parser.ASTJexlScript.jjtAccept(ASTJexlScript.java:55)
> org.apache.commons.jexl3.internal.Interpreter.interpret(Interpreter.java:210)
> org.apache.commons.jexl3.internal.Script$Callable.interpret(Script.java:364)
> org.apache.commons.jexl3.internal.Script$Callable.call(Script.java:372)
>    - locked org.apache.commons.jexl3.internal.Script$Callable@35595365
> java.util.concurrent.FutureTask.run(FutureTask.java:262)
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
> java.lang.Thread.run(Thread.java:745)
> {code}
> may be its worth rewriting the test to something like this
> {code}
>     public static class TestContext extends MapContext implements JexlContext.NamespaceResolver {
>         protected volatile boolean x = false;
>         public int runForever() {
>             while (true) {
>                 if (x) {
>                     break;
>                 }
>             }
>             return 1;
>         }
> ...
>     @Test
>     public void testCancelForever() throws Exception {
>         JexlScript e = JEXL.createScript("runForever()");
>         TestContext tctx = new TestContext();
>         Callable<Object> c = e.callable(tctx);
>         ExecutorService executor = Executors.newFixedThreadPool(1);
>         Future<?> future = executor.submit(c);
>         Object t = 42;
>         try {
>             t = future.get(100, TimeUnit.MILLISECONDS);
>             Assert.fail("should have timed out");
>         } catch (TimeoutException xtimeout) {
>             // ok, ignore
>             future.cancel(true);
>             tctx.x = true;
>         } finally {
>             executor.shutdown();
>         }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)