Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lightweight threads in Java?

Tags:

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.

like image 249
DagR Avatar asked Dec 21 '16 11:12

DagR


People also ask

What does lightweight mean in thread?

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.

Why thread is a lightweight process?

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.

What are the types of threads in Java?

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.

What are virtual threads Java?

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).


Video Answer


1 Answers

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.

like image 190
DagR Avatar answered Nov 16 '22 06:11

DagR