之前一直以为并发和并行是对立的,在单CPU上多任务(看似)同时进行是并发,而在多CPU上多个任务同时跑叫并行。所以当我看到Java并发编程这种说法的时候一直有个疑惑,因为Java的多线程明明可以使用多个线程却被人称呼为并发。
事实上,并发和并行描述的并不是一个方面
As you can see, concurrency is related to how an application handles multiple tasks it works on. An application may process one task at at time (sequentially) or work on multiple tasks at the same time (concurrently).
Parallelism on the other hand, is related to how an application handles each individual task. An application may process the task serially from start to end, or split the task up into subtasks which can be completed in parallel.
所有的并行都是并发,但并非所有的并发是并行
Java中的stream是并行