Skip to content

Method schedule on class java.util.concurrent.Executors$DelegatedScheduledExecutorService not allowed! #1264

Description

@dominicfreeston

version

0.8.2

platform

macOS 11.6

problem

Getting a Method schedule on class java.util.concurrent.Executors$DelegatedScheduledExecutorService not allowed! message when trying to call schedule on a scheduler.

repro

(import '[java.util.concurrent Executors TimeUnit])
(defn debounce [f delay-ms]
  (let [scheduler (Executors/newSingleThreadScheduledExecutor)
        task (atom nil)]
    (fn []
      (let [[old _] (reset-vals! task (.schedule scheduler f delay-ms TimeUnit/MILLISECONDS))]
        (when old
          (.cancel old true))))))
(def test-fn (debounce #(println "Hi!") 1000))
(test-fn)
(test-fn)
(test-fn)

expected behavior

Prints out "Hi!" once after about a second.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions