简体   繁体   中英

Multiple Threads concurrently running in JAVA

This question is regarding Multithreading in Java.

Multithreading is for the maximum utilisation of cpu. According to what I read, only one thread can be executed at a time. I believe that it it true for single processor system. Number of threads that can be executed simultaneously depends on what factors??

For Instance, If I am using 4 core processor, how many threads can be run concurrently??

Thanks in Advance.

For a 4-core processor 4 threads, or 8 if there's HyperThreading in the processor.

HyperThreading allows a core that's not running at 100% capacity to run 2 threads on a single core.

Threads are not limited by the number of available processors/cores. The operating system scheduler can switch back and forth between any number of threads on a single CPU. This is the meaning of preemptive multitasking .

Processor can normally run one thread at a time. When you have several processes running, your processor(s) switches between them very quickly, giving each one a slice of the processor's time. This gives an illusion of concurrency, but really everything is happening in serial.

So if you have 4 core processor the actually 4 thread can be run in parallel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM