併發和並行——一個一直以來的誤解

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章