Java中的异步IO? [英] Asynchronous IO in Java?

查看:23
本文介绍了Java中的异步IO?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了 java.nio 之外,java 中有哪些异步 io(基于套接字)选项?java.nio 是否也在后台使用线程(正如我认为 .NET 的 async-socket-library 所做的那样,也许它已被更改)还是使用正确的 select 调用是真正的"异步 io?

What options for async io (socket-based) are there in java other then java.nio? Also does java.nio use threads in the backround (as I think .NET's async-socket-library does, maybe it's been changed) or is it "true" async io using a proper select call?

推荐答案

Java 的 NIO 包(从 Java6 开始),仅通过 选择器s.Java7 有望与 NIO.2 一起发布,其中包括异步 I/O 支持.今天,最好的办法是使用框架.ARMistice 提到了米娜.这是其他一些.

Java's NIO package (as of Java6), provides support for non-blocking I/O only, via Selectors. Java7 is hopefully going to ship with NIO.2, which includes asynchronous I/O support. Today, your best bet is to make use of a framework. ARMistice mentioned Mina. Here are some others.

  1. 灰熊.这是 Sun 的 GlassFish 服务器的 I/O 核心.Grizzly 提供了进行异步读/写的工具(通过队列模型).它支持 TCP 和 UDP.我在几个项目中使用了 Grizzly.这个框架有我喜欢和不喜欢的地方,但要详细说明这确实是另一个话题.我要说的是,启动和运行某些东西非常容易,而 Grizzly 会为您完成很多繁重的工作.
  2. Netty.该项目来自 Mina 项目的原作者之一.我没有用过这个,所以我不知道它对异步 I/O 的支持.你应该看看.
  1. Grizzly. This is the I/O core for Sun's GlassFish server. Grizzly provides a facility for doing asynchronous reads/writes (via a queue model). It supports TCP and UDP alike. I've used Grizzly in a couple of projects. There are things I like and dislike about the framework, but to detail this is really another topic. I will say that it's quite easy to get something up and running and Grizzly does a lot of the heavy lifting for you.
  2. Netty. This project comes from one of the original authors of the Mina project. I haven't used this one so I don't know about its support for asynchronous I/O. You should take a look.

现在,关于您关于线程的问题,NIO Selectors 不使用线程进行非阻塞 I/O.在 JDK6 中,它们在 Windows 下使用 select() 和在较新的 Linux 内核上使用 epoll 工具.对于异步 I/O,线程细节取决于框架.

Now, with regard to your question about threads, NIO Selectors do not use threads for non-blocking I/O. In JDK6 they use select() under Windows and the epoll facility on newer Linux kernels. For asynchronous I/O, threading details depend on the framework.

这篇关于Java中的异步IO?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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