与非阻塞代码相比,阻塞代码有什么优势? [英] What are the advantages to blocking code over non-blocking code?

查看:56
本文介绍了与非阻塞代码相比,阻塞代码有什么优势?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习JavaScript和Node.我了解异步内容的工作原理.我明白为什么它可以显着加快速度.

I'm learning about JavaScript and Node. I understand how asynchronous stuff works. I get why it could significantly speed things up.

我看到其他语言(例如Ruby和Java?)被设计为阻塞的.为什么?

I see that other languages (like Ruby and Java?) are designed to be blocking. Why?

我有一个模糊的想法,您可以使用线程来处理需要很长时间的情况.与异步处理相比,这样做有什么优点和缺点?

I have a vague idea that you could use threads to handle situations where things take a long time. What are the advantages and disadvantages to this over doing things asynchronously?

推荐答案

阻塞或同步代码易于编写,并且具有默认的单线程行为.当每个任务都依赖于下一个任务时,阻塞代码才有意义.从历史上看,在使用多处理器和多线程之前,这是唯一可用的选择.

Blocking, or synchronous code is easy to write, and the default single threaded behavior. When each task depends on the next, then blocking code makes sense. Before multi-processors and multi-threading, this was the only available alternative, historically.

在可以并行执行多个任务的情况下,创建了非阻塞,异步,多线程编程,以提高性能.这样可以提高性能,但以增加复杂性为代价,使代码维护更加困难.

Non-blocking, asynchronous, multi-threaded programming was created to improve performance in the case where more than one task could be performed in parallel. This improves performance, but at the expense of adding complexity, making code maintenance more difficult.

这篇关于与非阻塞代码相比,阻塞代码有什么优势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆