Created
April 22, 2022 00:49
-
-
Save Chouser/d07a4e883f637e2b6b19d979fe3688f3 to your computer and use it in GitHub Desktop.
core async reseting experiment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns io.chouser.experiment | |
(:require [clojure.core.async :as async])) | |
(defn bang [] | |
(future | |
(dotimes [i 10] | |
(async/go | |
(print (str "start " i "\n")) (flush) | |
(Thread/sleep 20000) | |
(prn :done i))))) | |
(require '[clojure.core.async.impl.dispatch :as impl.d] | |
'[clojure.core.async.impl.exec.threadpool :as tp]) | |
(import '(java.util.concurrent ThreadPoolExecutor)) | |
(defn new-dispath-executor [_] | |
(delay (tp/thread-pool-executor #(.set ^ThreadLocal @#'impl.d/in-dispatch true)))) | |
(defn reset-dispatch-executor [] | |
(let [old-executor ^ThreadPoolExecutor @impl.d/executor | |
executor-svc-field (doto (.getDeclaredField (type old-executor) "executor_svc") | |
(.setAccessible true)) | |
thread-pool-executor (.get executor-svc-field old-executor)] | |
(prn :largest (.getLargestPoolSize thread-pool-executor) :active (.getActiveCount thread-pool-executor)) | |
(prn :shutdown (.shutdownNow thread-pool-executor)) | |
(alter-var-root #'impl.d/executor new-dispath-executor))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment