Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,22 @@ | ||
# 不要阻塞我! | ||
|
||
除了极少数例外 (一些文件系统操作的“同步”结束),没有一个 Vert.x Api 阻塞调用线程。 | ||
|
||
如果可以立即提供的结果,它将立即返回,你通常会提供一个handle来接收过一段时间的事件。 | ||
|
||
由于Vert.x API没有任何阻塞的线程,这意味着你可以使用Vert.x来处理只是使用小数目线程的大量并发。 | ||
|
||
常规阻塞API使用线程可能会阻塞: | ||
|
||
* 从socket读取数据 | ||
* 向磁盘写入数据 | ||
* 向收件人发送一条消息,等待答复。 | ||
* … | ||
|
||
在所有上述情况下,当您的线程正在等待结果时它不能做别的-这是实际上是浪费。 | ||
|
||
这意味着,如果你需要大量的并发使用阻塞 APIs,然后你需要大量的线程,以防止您的应用程序停止工作。 | ||
|
||
线程在他们所需要的内存(例如栈)和上下文切换方面有开销。 | ||
|
||
对于许多现代应用程序所需要的并发水平,阻塞的方法不能按比例缩放。 |