Java threads not actually running in parallel?

So far I have got the impression that two threads that run at the same time are also running in parallel (both run their part of the codes at the same time), but I recently read some documentation and I realized that they actually accept includes the execution of its code itself, so there is no piece of code for the first thread executing at the same time as a piece of code from the second thread. Do I understand correctly?

If so, how is multithreading faster than a single thread execution? I ask this because the only difference is that one thread executes the code sequentially, while multithreading can execute in turn, but it should still take the same amount of time, since nothing is done in parallel

+4
source share
5 answers

a) on multiprocessor machines, threads can run in parallel (one per processor)

b) Thread.sleep() - .., . , , .

+7

Java- , JVM . 2 , , . , , , .

+3

, Java ( , CPython). , , .

, PI .., , ( 2 = x2, 4 = x4 ..)

:
, - . , , , . , .

EDIT2: ( ) , , 100% . , , , . , . , 100% .

+2

, CPU, . , , , , .

, , ? Mutlithreading . , - , .


, http://javasolutionsonline.blogspot.in/p/java-concurrency.html

+1

umm..threads work in parallel ... but not on your regular PCs that had single cores. if you have a multi-core chip or many processors, then they can work in parallel. imagine that one thread runs on each of the four cores ...

flow has many other benefits, as you already know

-1
source

All Articles