Threads on different Hardware
When I fist learned about Java threads, I've been told that, the multi threading is not real. That is, there is a single CPU and the OS does a context switch between threads to simulate multi threading.
Nowdays, we have i3, i5 i7, dual core, core2dou and etc...
So when I have a Java program that uses a thread pool in size 10 (for example), Assuming the thread pool is full with threads ready to run, How many threads will run in the same time (for real) in i5 computer with 2 cores?
最多会有2个线程同时执行(2个核心),但还有更多的线程可能会被安排执行(等待cpu)
In the beginning Java had 'green' threads, so the thread scheduling was done in the jvm. But since a very long time Java has native threads. In any case, Java can make use of all your cores if you provide enough threads.
PS: If you core supports Hyper threading, than the OS will see twice the number of cores. This is useful if your thread is stalled for eg a memory read so another thread can run. At home I have a 4 core Xeon machine, but with Hyperthreading enabled, my operating system will see 8 cores. But effectively only 4 threads can run concurrently.
链接地址: http://www.djcxy.com/p/36876.html上一篇: 使用“反应性本机”与我们现有的代码
下一篇: 线程在不同的硬件上