Skip to content

Commit 35e7ad9

Browse files
committed
vthread es when available
1 parent c56fd02 commit 35e7ad9

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/main/clojure/clojure/core/async/impl/dispatch.clj

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,27 @@
7171
[workflow]
7272
(Executors/newCachedThreadPool (counted-thread-factory (str "async-" (name workflow) "-%d") true)))
7373

74+
(def virtual-threads-available?
75+
(try
76+
(Class/forName "java.lang.Thread$Builder$OfVirtual")
77+
true
78+
(catch ClassNotFoundException _
79+
false)))
80+
81+
(defn- make-io-executor
82+
[]
83+
(if virtual-threads-available?
84+
(-> (Thread/ofVirtual)
85+
(Thread$Builder/.name "async-vthread-io-" 0)
86+
.factory
87+
Executors/newThreadPerTaskExecutor)
88+
(make-ctp-named :io)))
89+
7490
(defn ^:private create-default-executor
7591
[workload]
7692
(case workload
7793
:compute (make-ctp-named :compute)
78-
:io (make-ctp-named :io)
94+
:io (make-io-executor)
7995
:mixed (make-ctp-named :mixed)))
8096

8197
(def executor-for

0 commit comments

Comments
 (0)