Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum number of threads than can run concurrently in java on a CPU

Please I got confused about something. What I know is that the maximum number of threads that can run concurrently on a normal CPU of a modern computer ranges from 8 to 16 threads. On the other hand, using GPUs thousands of threads can run concurrently without the scheduler interrupting any thread to schedule another one. On several posts as: Java virtual machine - maximum number of threads https://community.oracle.com/message/10312772 people are stating that they run thousands of java threads concurrently on normal CPUs. How could this be ?? And how can I know the maximum number of threads that can run concurrently so that my code adjusts it self dynamically according to the underlying architecture.

like image 324
user3060396 Avatar asked Feb 08 '14 18:02

user3060396


People also ask

How many threads can concurrently Java?

4.2. On Windows machines, there's no limit specified for threads. Thus, we can create as many threads as we want, until our system runs out of available system memory.

How many threads can a CPU run at once?

A single CPU core can have up-to 2 threads per core. For example, if a CPU is dual core (i.e., 2 cores) it will have 4 threads.

Can we create 1000 threads in Java?

By the way in windows you can't create more then 1000 since windows can't handle the threads very well, but you can create 1000 threads in linux if you leverage with NPTL. So many persons told you java couldn't handle large concurrent job processings that wasn't 100% true.

Can multiple threads run concurrently?

Concurrency and Parallelism In the same multithreaded process in a shared-memory multiprocessor environment, each thread in the process can run concurrently on a separate processor, resulting in parallel execution, which is true simultaneous execution.


1 Answers

There is hardware and software concurrency. The 8 to 16 threads refers to the hardware you have - that is one or more CPUs with hardware to execute 8 to 16 threads parallel to each other. The thousands of threads refers to the number of software threads, the scheduler will have to swap them out so every software thread gets its time slice to run on the hardware.

To get the number of hardware threads you can try Runtime.availableProcessors().

like image 72
josefx Avatar answered Oct 18 '22 20:10

josefx