- 浏览: 830824 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (379)
- struts (5)
- hibernate (16)
- spring (16)
- ssh (20)
- MySQL (16)
- 数据库脚本 (2)
- DownLoad (1)
- GAE (5)
- Java (103)
- LoadRunner (2)
- VF (1)
- 学习资料 (24)
- 软件使用 (21)
- 通信类 (4)
- 生活 (3)
- J2ME (1)
- 心理学 (1)
- Linux (26)
- Android (3)
- Oracle (1)
- 面向对象概念&面试准备 (11)
- ExtJs (2)
- Google Map (1)
- Flex (47)
- 算法研究 (1)
- share (20)
- python (1)
- MongoDB (7)
- centos6 (13)
- C++ (8)
- DB2 (3)
- C# (1)
- 代码片段 (24)
- Lucene (2)
- php (1)
- NodeJS (1)
- Express (1)
最新评论
-
shua1991:
已阅,我表示同意。
Eclipse统计代码行数 -
nakedou:
写的不错,挺详细的
在CentOS中使用 yum 安装MongoDB及服务器端配置 -
sjp524617477:
好方法
Eclipse统计代码行数 -
simpletrc:
<script>ale ...
Java写到.txt文件,如何实现换行 -
csdn_zuoqiang:
Apache Ftp Server,目前是1.0.4,非常好的 ...
Apache FtpServer在64位系统下服务不能启动解决方法
In a previous tip, I discussed a simple file copy algorithm in context to the best way to move a directory of files (see IO: Moving a Directory ). The algorithm I posted was something of this sort: public static void copyFile(File source, File dest) throws IOException { if(!dest.exists()) { dest.createNewFile(); } InputStream in = null; OutputStream out = null; try { in = new new FileInputStream(source); out = new FileOutputStream(dest); // Transfer bytes from in to out byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } finally { if(in != null) { in.close(); } if(out != null) { out.close(); } } } One of the things to note in this algorithm is the verbosity and explicitness of the code. The code specifically defines a byte[] buffer, and sets the size to 1 kilobyte, and then it simply does kilobyte-at-a-time copies. The first potential problem with this is that the amount of optimal buffering isn't neccessarily 1 kilobyte. In addition to that, for this code to work, Java IO code must read data from the file system, bring it up into JVM memory, and then push it back down to the filesystem through Java IO. We all remember when Java 1.4 came out that it brought the java.nio package with it - most of us also remember how that was pretty much it - after that there wasn't a whole lot of noise regarding 'NIO'. It's really a shame - Java NIO has the potential to really improve performance in a lot of areas. File copies is just one of them. Here is the basic file-to-file copy algorithm re-implemented using 'NIO': public static void copyFile(File sourceFile, File destFile) throws IOException { if(!destFile.exists()) { destFile.createNewFile(); } FileChannel source = null; FileChannel destination = null; try { source = new FileInputStream(sourceFile).getChannel(); destination = new FileOutputStream(destFile).getChannel(); destination.transferFrom(source, 0, source.size()); } finally { if(source != null) { source.close(); } if(destination != null) { destination.close(); } } The first thing you'll notice about this implementation is the difference in core copying logic: byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } ... becomes: destination.transferFrom(source, 0, source.size()); Note that there is no reference to the buffering used or the implementation of the actual copy algorithm. This is key to the potential performance advantages of this algorithm. The 'transferFrom' algorithm has the advantage of being able to be optimized to a much higher level than most of us would want to try. For one thing, because of the design of the interacting objects, chances are good that on most platforms the copy request can be deferred directly to the underlying operating system. Let it be known that in most cases the OS will be faster at copying files than Java. Just the same, even if it can't actually defer directly to the OS for the copy, because the transferFrom algorithm is related to the underlying channel implementation, it can be optimized for the platform, context, and channel type, it can use native method calls, and do many other fancy things. Long story short, the transferFrom algorithm can be optimized and optimized and optimized (and is ). Just to verify, I filled a folder with a ton of small and large files, just to see what would happen. It seems, on average, that there is about a 33% improvement in performance (yes, 1/3rd !!!) from the rather simple copy algorithm above. Not too shabby!
http://www.javalobby.org/java/forums/t17036.html
发表评论
-
微信JS
2013-10-26 21:17 2039<div class="iteye-blog- ... -
ubuntu下MySQL用source命令导入sql文件出现乱码解决方法
2012-11-18 23:46 1483首先建立数据库的时候指明数据库编码如: CREA ... -
RandomAccessFile
2012-10-18 18:16 941public void run() { try { ... -
java中多种方式读文件
2012-10-18 16:53 925java中多种方式读文件一、多种方式读文件内容。1、按字节读取 ... -
FileChannelMain
2012-10-15 18:12 1072package scan; import java ... -
Apache FtpServer在64位系统下服务不能启动解决方法
2012-06-10 21:29 6799Apache FTPServer是一款用Java开发的 ... -
Java 集合类
2012-06-07 22:03 1565Java 集合类 1. 为什么要了解J ... -
short、int、long与byte之间的转换工具类
2012-05-31 11:05 4476/** * 各基础类型与byte之间的转换 * ... -
Linux Mint 13 配置JAVA 环境
2012-05-24 22:35 26190.1--下载 JAVA ... -
FatJar+Exe4j+Inno Setup 生成可执行的exe文件
2012-04-17 10:54 14241、fatjar 是Eclipse的一个免费的插件。它的 ... -
一个开源的高效全文检索框架(懂C语言可以进来研究下原理)
2012-04-07 23:03 1342示例地址: http://rbbs.sourcefor ... -
批量删除删除CVS文件夹
2012-04-06 16:11 2002@echo On @Rem C:/Users/XPan ... -
JPanel JTextField add Focus 获取焦点解决方案
2012-03-30 21:29 2979public class TabPagePanel ex ... -
JList List<E> Page 分页
2012-03-30 21:28 1730package view.retrieve.comps. ... -
JButton setAction的BUG
2012-03-23 10:53 1276今天在使用JButton的时候,想用setText()setI ... -
自定义JTabbedPane皮肤
2012-03-22 12:05 4709package ui; import java.awt. ... -
两个工具类
2012-03-17 21:27 863package com.retrieve.utils; ... -
两个工具类
2012-03-17 21:27 0package com.retrieve.utils; ... -
mysql、sqlserver、oracle分页,java分页统一接口实现
2012-03-13 17:56 0定义: pageStart 起始页,pageEnd 终止页, ... -
Invalid command: InetLoad::load
2012-03-06 16:41 1284Invalid command: InetLoad::load ...
相关推荐
一站式学习Java网络编程 全面理解BIO:NIO:AIO1
java nio ppt java.nio: High Performance I/O for Java
Maven坐标:org.apache.httpcomponents:httpcore-nio:4.4.6; 标签:apache、httpcomponents、nio、httpcore、jar包、java、中英对照文档; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可...
Maven坐标:org.apache.httpcomponents:httpcore-nio:4.4.14; 标签:apache、httpcomponents、httpcore、nio、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览...
NULL 博文链接:https://conkeyn.iteye.com/blog/523234
Java NIO: Channels and Buffers(通道和缓冲区) 标准的IO基于字节流和字符流进行操作的,而NIO是基于通道(Channel)和缓冲区(Buffer)进行操作,数据总是从通道读取到缓冲区中,或者从缓冲区写入到通道中。 ...
postgres-nio::elephant:用于PostgreSQL非阻塞,事件驱动的Swift客户端
Java NIO: Channels and Buffers(通道和缓冲区) 标准的IO基于字节流和字符流进行操作的,而NIO是基于通道(Channel)和缓冲区(Buffer)进行操作,数据总是从通道读取到缓冲区中,或者从缓冲区写入到通道中。 ...
nio:用于Nim语言的迷你服务器框架
o Clojure对java.nio的支持。 将clojure.java.io的输入流,输出流和复制功能扩展到java.nio类。 定义新的强制功能缓冲区,字节缓冲区,字符缓冲区,双缓冲区,浮点缓冲区,整数缓冲区,长缓冲区,短缓冲区,通道,可...
Using NIO to copy Java file fast
Maven坐标:org.jboss.xnio:xnio-nio:3.8.4.Final; 标签:jboss、xnio、nio、jar包、java、中文文档; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的...
但 Java 在后期版本中引入了 java.nio.file 库来提高 Java 对文件操作的能力。还增加的流的功能,似乎使得文件变成更好用了。所以本章,我们就来主要介绍 java.nio.file 中常用的类和模块,大致如下: Path 路径:...
MQTT NIO 一个基于Swift NIO的MQTT 3.1.1客户端,通过NIOSSL和NIOTransportServices支持NIOTransportServices(iOS必需),WebSocket连接和TLS。 MQTT(消息队列遥测传输)是IBM开发的轻量级消息协议,于1999年...
nio java8 nio使用的总结 目录 1. NIO_NIO 与 IO 区别 NIO支持面向缓冲区的、基于通道的IO操作 IO NIO 面向流(Stream Oriented) 面向缓冲区(Buffer Oriented) 阻塞IO(Blocking IO) 非阻塞IO(NonBlocking ...
ReadWriter} nio的Copy方法同时从io.Reader复制到提供的nio.Buffer,然后从nio.Buffer复制到io.Writer。 这样,阻止写入不会降低io.Reader的速度。 import ( "github....
:speech_balloon: o Nio是即将推出的iOS 客户端。 目前,该项目仍在进行中。 有关更新,请在我们的矩阵房→ 。 想试一试吗? 加入公共 。入门由于仁王使用斯威夫特软件包管理器,所有你需要做的是克隆的项目,在...
yubo-java-nioNIO 直接缓冲区 VS 非直接缓冲区直接缓冲区1、直接缓冲区最适合I/O 2、创建成本比非直接缓冲区高 3、直接缓冲区使用的内存是通过调用原生的、操作系统特定的代码来分配的 4、内存存储区域不受限制垃圾...
ZIO-NIO CI 释放快照不和谐 Java NIO的ZIO接口。 Java NIO是不安全的,例如,隐藏IO操作中的实际错误并在IO成功/不成功时仅给您提供true / false值,这可能会让您大吃一惊。 另一方面,ZIO-NIO包含ZIO效果,环境,...
也许很多朋友在学习NIO的时候都会感觉有点吃力,对里面的很多概念都感觉不是那么明朗。在进入Java NIO编程之前,我们先来讨论一些比较基础的知识:I/O模型。下面本文先从同步和异步的概念 说起,然后接着阐述了阻塞...