the cost of creating Java Threads, a plus for Kotl...
# feed
d
the cost of creating Java Threads, a plus for Kotlin + Coroutines https://dzone.com/articles/java-threads-may-not-be-memory-efficient
This study clearly indicates that memory is allocated to threads at the time of creation, and memory is not allocated based on the thread’s runtime demand. Both hyper working threads and almost dormant threads consume the same amount of memory. Modern Java applications tend to create hundreds (sometimes thousands) of threads. But most of those threads are in a WAITING or TIMED_WAITING state and do nothing.
k
interesting experiment. entirely predictable result though. that's just how the stack works.
d
It looks like they run it using very old (as in Java 8 ) version which was eagerly allocating the memory to the threads. It does not do that in Java 11. see: https://dzone.com/articles/how-much-memory-does-a-java-thread-take
k
they changed the stack to support dynamic sizing?
interesting. pthreads works in the same way as the older Java model.
s
Dynamic stack sizing is will be available in project loom, which will allow us to create millions of threads

https://youtu.be/7GLVROqgQJY