java - Difference between processors and threads -


this question has answer here:

i using parallel stream of java 8, don't understand 1 thing:

i have machine 8 processors...

intstream.range(0, 9).parallel().foreach(i -> {     int cnt = 0;     while (system.currenttimemillis() < rununtil)         cnt++;     system.out.println(i + ": " + cnt); }) 

does mean can use 8 threads?

the above code runs 8 in parallel , next waiting, if use custom thread pool using forkjoinpool tasks more 8 running in parallel.

forkjoinpool forkjoinpool = new forkjoinpool(17); forkjoinpool.submit(()->intstream.range(0, 17).parallel().foreach(i -> {     int cnt = 0;     while(system.currenttimemillis() < rununtil)         cnt++;     system.out.println(i + ": " + cnt); })).get(); 

the above code runs 16 in parallel. if can use more 8 threads in 8 processor machine, max number of threads can use.

edit 1-does mean max number of threads can use 2*available processor's?

you can run x-amount of threads inside 1 single process. processor in other words cpu unit runs down. can check resource monitor on windows see how many threads running in 1 process.

for example chrome browser running in 3 processes while having 20 threads respectively. in other words can start many threads cpu power/memory etc. allows.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -