Scala / Java 中的 NIO 问题是什么?

发布于 2024-10-26 20:53:25 字数 594 浏览 1 评论 0原文

在网上搜索 jvm 中的并发性时,我发现了有关搜索 Scala / Java 的非阻塞 IO 库的问题。

问题出在哪里?如果我想发送一些东西到文件/套接字,我可以启动单独的线程来完成这项工作。

我知道使用基于事件的线程可能会出现问题 - 因为整个系统可能会被阻塞。但它引用了 JVM/Scala 吗?

添加
如果我错了,请纠正我:
我认为当您需要以异步方式调用某些 IO 函数时,它需要进入单独的进程或系统(重)线程。我说得对吗?
因此,有关用通用语言解决此类问题的所有问题都涉及创建和管理单独的进程或线程。因此,该语言的唯一便利是创建一些线程池,这些线程池将分配给异步 IO 操作。

所以我的假设是。
句子:语言 X 比 Y 更好,因为调用异步 IO 操作不会阻塞虚拟机是错误的,因为在每种支持系统线程的语言中都可以管理 NIO,唯一的区别是语言X 通过内置库/语言功能对此提供了更好的支持。

  1. 这个假设是真的吗?
  2. 某些语言可以在没有操作系统支持的情况下实现NIO吗? (通过进程/线程)

While searching the web for concurrency in jvm I found questions about searching Non-blocking IO library for Scala / Java.

What is the problem about? If I want to send something to file / socket I can launch separate thread which make the job.

I know there could be problem using event based threads - because whole system could be blocked. But does it reference to JVM/ Scala?

ADDED:
Please correct me if I'm wrong:
I think that when you need to call some IO function in asynchronous way it need to go into separate process or system (heavy) thread. Am I right?
So - all the questions about solving this kind of thing in common languages goes into creating and managing separate process or threads. So the only facilitate from the language is to create some pool of threads which will be assigned to IO operations in async.

So my hypotheses is.
Sentence: Language X is better then Y because calling async IO operation dosen't block the virtual machine is false because in every language that support system threads there is possibility to manage NIO, the only difference is that language X has better support for this through builtin libraries / language features.

  1. Is this hypothese Truth?
  2. Can some language achieve NIO without os system support? (through processes / threads)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我只土不豪 2024-11-02 20:53:25

Scala 有很多并发工具,NIO 有一些非阻塞 IO 工具。因此,有很多优秀的库可以帮助连接这些点也就不足为奇了:

Scala has a bunch of tools for concurrency, and NIO has a few tools for non-blocking IO. So, it should come as no surprise that there are a lot of great libraries that help connect the dots:

  • Finagle

    ... a library for building
    asynchronous RPC servers and clients
    in Java, Scala, or any JVM language.
    Built atop Netty, Finagle provides a
    rich set of tools that are protocol
    independent.

  • Akka is a pretty nice, featureful actors/concurrency/services package which also uses Netty for their built-in remoting functionality

  • Naggati2 is another one from Twitter, also built on Netty, not sure if it's being superseded by Finagle though.

狼性发作 2024-11-02 20:53:25

这是最近一篇有趣的博客文章,可能会对您有所帮助: http://jim-mcbeath.blogspot.com/2011/03/java-nio-and-scala-continuations.html

Here is an interesting recent blog post that may help you: http://jim-mcbeath.blogspot.com/2011/03/java-nio-and-scala-continuations.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文