from visual vm running the above: live threads 8081 and daemon threads 8080
and dumped into the repl:
> Exception in thread "async-dispatch-133" Exception in thread "async-dispatch-132" Exception in thread "async-dispatch-131" Exception in thread "async-dispatch-130" Exception in thread "async-dispatch-128" Exception in thread "async-dispatch-127" Exception in thread "async-dispatch-126" java.lang.AssertionError: Assert failed: No more than 1024 pending takes are allowed on a single channel.
(< (.size takes) impl/MAX-QUEUE-SIZE)
at clojure.core.async.impl.channels.ManyToManyChannel.take_BANG_(channels.clj:235)
at clojure.core.async.impl.ioc_macros$take_BANG_.invokeStatic(ioc_macros.clj:988)
at clojure.core.async.impl.ioc_macros$take_BANG_.invoke(ioc_macros.clj:987)
at investigate$fn__9405$fn__9414$state_machine__6606__auto____9415$fn__9417.invoke(NO_SOURCE_FILE:1)
at investigate$fn__9405$fn__9414$state_machine__6606__auto____9415.invoke(NO_SOURCE_FILE:1)
at clojure.core.async.impl.ioc_macros$run_state_machine.invokeStatic(ioc_macros.clj:978)
at clojure.core.async.impl.ioc_macros$run_state_machine.invoke(ioc_macros.clj:977)
at clojure.core.async.impl.ioc_macros$run_state_machine_wrapped.invokeStatic(ioc_macros.clj:982)
at clojure.core.async.impl.ioc_macros$run_state_machine_wrapped.invoke(ioc_macros.clj:980)
at investigate$fn__9405$fn__9414.invoke(NO_SOURCE_FILE:1)
at clojure.lang.AFn.run(AFn.java:22)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at clojure.core.async.impl.concurrent$counted_thread_factory$reify__479$fn__480.invoke(concurrent.clj:29)
at clojure.lang.AFn.run(AFn.java:22)
at java.base/java.lang.Thread.run(Thread.java:830)
... couple hundred liens that look like the above...
Exception in thread "async-dispatch-99" [37.890s][warning][os,thread] Failed to start thread - pthread_create failed (EAGAIN) for attributes: stacksize: 1024k, guardsize: 4k, detached.
Exception in thread "async-dispatch-8177" java.lang.OutOfMemoryError: unable to create native thread: possibly out of memory or process/resource limits reached
Its true that you are creating 8000 threads but you only have 8 alive at any time. You're piling up tons of pending takes which are unsatisfied and running into core.async's 1024 limit.
https://github.com/clojure/core.async/blob/master/src/main/clojure/clojure/core/async/impl/protocols.clj#L13
So what you're doing is creating thousands of threads and killing them immediately, with many more jumping into the breach based on the following FixedThreadPool
```
(defn thread-pool-executor
([]
(thread-pool-executor nil))
([init-fn]
(let [executor-svc (Executors/newFixedThreadPool
@pool-size
(conc/counted-thread-factory "async-dispatch-%d" true
{:init-fn init-fn}))]
(reify impl/Executor
(impl/exec [this r]
(.execute executor-svc ^Runnable r))))))
```