You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Tim Yates (Jira)" <ji...@apache.org> on 2020/07/24 15:10:00 UTC

[jira] [Created] (GROOVY-9656) ExecutorService as a @Delegate calls the Runnable submit instead of the Callable one

Tim Yates created GROOVY-9656:
---------------------------------

             Summary: ExecutorService as a @Delegate calls the Runnable submit instead of the Callable one
                 Key: GROOVY-9656
                 URL: https://issues.apache.org/jira/browse/GROOVY-9656
             Project: Groovy
          Issue Type: Bug
          Components: Compiler
    Affects Versions: 2.5.13, 3.0.5
            Reporter: Tim Yates


When {{ExecutorService}} is used with the {{@Delegate}} annotation, then casting a Closure to a {{Callable}} doesn't seem to call the correct method (we suspect it's calling the {{Runnable}} method)

 

Given the following script:
{code:java}
import java.util.concurrent.Callable
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.concurrent.Future
import java.util.concurrent.TimeUnit

class MyService {
    @Delegate ExecutorService delegateExecutorService = Executors.newCachedThreadPool()
}

def test(ExecutorService s) {
    println s.submit { 42 }.get()
    println s.submit([call: { 42 }] as Callable).get()
    println s.submit({ 42 } as Callable).get()
    s.shutdownNow()
}

println "Delegated ExecutorService"
test(new MyService())

println()

println "Actual ExecutorService"
test(Executors.newCachedThreadPool())
{code}

The output is:

{code}
Delegated ExecutorService
null
42
null

Actual ExecutorService
null
42
42
{code}

Whereas I was expecting the first delegated result to be the same as calling the actual executor service...

Apologies if this is a dupe, or documented, I did try and look, but to no avail

Cheers

Tim



--
This message was sent by Atlassian Jira
(v8.3.4#803005)