Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-9656

ExecutorService as a @Delegate calls the Runnable submit instead of the Callable one

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.0.5, 2.5.13
    • None
    • Compiler
    • None

    Description

      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:

      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())
      

      The output is:

      Delegated ExecutorService
      null
      42
      null
      
      Actual ExecutorService
      null
      42
      42
      

      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

      Attachments

        Activity

          People

            Unassigned Unassigned
            tim_yates Tim Yates
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: