之前一直以爲併發和並行是對立的,在單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是並行