Is there any JSR or other serious initiative to create lightweight threads in Java? Something similar to Golang's goroutines or Erlang processes.
Java threads are known for their heavy weight. Something like 512-1024 kb per thread is used so this limits the maximum number of threads. Context switching between java threads also takes a "long" time.
I've heard of Quasar "fibers" (http://docs.paralleluniverse.co/quasar/) which are lightweight threads implemented as a lib. They seem a bit tricky to use though and haven't caught a lot of interest.
Ideally lightweight threads should be built into the core of the JVM.
For example, in programming, a lightweight thread is a program thread (an instance of use) that takes fewer instructions to keep track of than an ordinary thread, thus enabling the program to handle more users at the same time at an acceptable performance level.
Threads are sometimes called lightweight processes because they have their own stack but can access shared data. Because threads share the same address space as the process and other threads within the process, the operational cost of communication between the threads is low, which is an advantage.
Java offers two types of threads: user threads and daemon threads. User threads are high-priority threads. The JVM will wait for any user thread to complete its task before terminating it.
In Java, Virtual threads (JEP-425) are JVM-managed lightweight threads that will help in writing high throughput concurrent applications (throughput means how many units of information a system can process in a given amount of time).
There is a proposal for lightweight threads ("fibers") on the JVM called Project Loom: http://cr.openjdk.java.net/~rpressler/loom/Loom-Proposal.html
It's in its early stages, nothing released yet, but still something to keep an eye on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With