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

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

问题描述

有关异步IO(插座型)是存在于其他的Java然后java.nio的选择是什么?也做java.nio中的底色使用线程(我认为.NET的异步套接字库做,也许它已经改变)或者是真正的异步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的),提供的非阻塞支持I / O 的唯一,通过的选择秒。 java7目录是希望要与NIO.2,其中包括异步I / O支持出货。如今,最好的办法是利用一个框架。停战提到米娜。这里有一些其他。

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核心。灰熊提供了这样一个异步设施读/写操作(通过一个队列模型)。它支持TCP和UDP的一致好评。我用灰熊在几个项目。有些事情我喜欢和不喜欢的框架,但细节,这是真正的另外一个话题。我会说,这是很容易得到的东西和运行,灰熊做了很多繁重的工作适合你。

  2. Netty的。该项目来源于对米娜项目的原作者之一。我没有使用过这一个,所以我不知道关于它的异步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 on the Mina project. I haven't used this one so I don't know about about its support for asynchronous I/O. You should take a look.

现在,关于你对线程的问题,NIO选择器不要使用非阻塞I / O线程。在JDK6他们使用选择() Windows和较新的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.

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

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