单线程的NodeJS和Go语言相对于Java的多线程有哪些优势?

huangapple go评论91阅读模式
英文:

How are Single thread of NodeJS and Go lang better than multi thread of Java?

问题

我想比较NodeJS、Go语言和Java。我在搜索并发控制方面的信息。结果是Java的并发控制是多线程的,而NodeJS和Go语言的并发控制是单线程的。所以,我想知道NodeJS和Go语言的单线程相比Java的多线程有什么优势?

有人可以帮助我吗?非常感谢每一条评论。

英文:

I wanna compare NodeJS, Go lang,and Java. I search about concurrency control. The result are the concurrency control of Java is multi thread, the concurrency control of NodeJS and Go lang are single thread. So, I wanna know how are Single thread of NodeJS and Go lang better than multi thread of Java ?

Can anyone help me ?
Ty for every comment.

答案1

得分: 12

NodeJS是单线程的。它采用事件并发模型,在代码中使用回调函数序列。Java具有真正的多线程模型,其中每个程序线程映射到操作系统线程。这种模型的成本是堆栈切换。Go也是多线程的,但它使用用户空间或“绿色线程”,由运行时调度器将其映射到一个或多个操作系统线程。这些线程轻量级且切换成本较低,您可以创建数十万个Go协程而不会出现任何问题。使用Java模型,您可以更精确地控制操作系统资源共享。

英文:

NodeJS is single threaded. It has event concurrency model which bring sequence of callbacks in the code. Java has true multi-threaded model where each program thread mapped on OS thread. The cost of this model is stack switch. Go is multi-threaded also but it uses user-space or 'green threads' which are mapped to one or more OS threads by runtime sheduler. Such treads are light and switch cost is less, you can spawn hundreds of thousands of go routines without any problems. With Java model you have in hand more precise control around OS resource sharing.

huangapple
  • 本文由 发表于 2015年5月13日 17:36:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/30210935.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定