ExecutorService BlockingQueue I

Опубликовано: 18 Июнь 2026
на канале: Rabi Sankar Podder
283
3

GIT link :: https://github.com/djrabi007/multithr...

CPU intensive operation (too many thread is NOT Good idea)
 e.g Algorithm,Cryptographic operation .... (They will take lot of CPU)
 In Java ,1 Thread --- 1 OS Thread...
 If we have CPU with 4 core...only 4 thread can Run at a time.. (same time t0 ....sometime t1,,...sometime t2 ....bump it up ...)
 if We have 1K threads... but CPU itself only allow 4 thread at a time...
 So,Pool size should be same as CPU core size i.e. 4
 Here we have 4 thread and CPU core size is 4. all 4 core will be occupied by all 4 threads (t0,t1,t2,t3)


Non-CPU intensive operation (too many thread is Good idea)
e.g IO operation,Http webservice call..... wait for the OS to get response....
o 4 Core CPU ...
o All the threads (t0,t1,t2,t3) are waiting for Response
o No Threads available to fetch the task from BlockingQueu.....
o Solution - Give Size of pool large 100 thread (more thread than CPU core i.e 4 )