Reputation:
Some threads such as this one say that the threads I can run on my machine is 4. Does this mean if I created a multi-threaded java program, I can create only 2 x 2 x 1 = 4
threads without any blocking or performance issues ?
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 2
Core(s) per socket: 2
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 69
Model name: Intel(R) Core(TM) i7-4500U CPU @ 1.80GHz
Stepping: 1
CPU MHz: 926.041
CPU max MHz: 3000.0000
CPU min MHz: 800.0000
BogoMIPS: 4788.55
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 4096K
NUMA node0 CPU(s): 0-3
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts md_clear flush_l1d
Upvotes: 0
Views: 53
Reputation: 102812
You can run as many threads as you want; you are limited only by your memory (as each thread needs a little memory for tracking purposes; primarily, the stack size). A thousand threads is generally no problem, for example.
That output suggests that at any given time, 4 of your threads will actually be actively processing statements and all others will be waiting around. Note that threads are 'pre-emptive', meaning, they run for a bit and are then automatically frozen so that another one can have a turn. Furthermore, if a thread 'blocks' for any reason (blocks = doing something that needs to wait for something to finish, and it's not the CPU, then other threads get their turn right away.
Think of:
The short of it? Just make as many threads as you want, and treat them as if they all run simultaneously. There's no reason to worry about performance or if this is the right approach until you get to over a thousand of them.
Upvotes: 3