Java NIO
Why NIO ?
http://onjava.com/pub/a/onjava/2002/09/04/nio.html?page=1
Java developers might ask: why introducing a new technology to handle sockets? What's wrong with the Java 1.3.x sockets? Suppose you would like to implement a server accepting diverse client connections. Suppose, as well, that you would like the server to be able to process multiple requests simultaneously. Using Java 1.3.x, you have two choices to develop such a server:
Implement a multithread server that manually handles a thread for each connection.
Using an external third-party module.
Both solutions work, but adopting the first one -- the whole thread-management solution, with related concurrency and conflict troubles -- has to be developed by programmer. The second solution may cost money, and it makes the application dependent on a non-JDK external module. By means of the nonblocking socket, you can implement a nonblocking server without directly managing threads or resorting to external modules.
In internal benchmarks, the router was able to handle up to 10,000 clients with no significant drop in throughput. For comparison, we implemented a version based on the thread-per-client model, which was only able to reach 3,000 clients, with a significant drop in throughput as the number of clients increased. (Thread Pool not alleviate it)
http://java.sun.com/j2se/1.4.2/docs/guide/nio/example/index.html
http://rox-xmlrpc.sourceforge.net/niotut/
Q: use loop to read or read assembling ?
/**
* several reads
*/
ByteBuffer buffer = ByteBuffer.allocate(10 * 1024);
...
int readBytes = sc.read(inBuffer);
buffer.put(inBuffer);
int target = 1024;
if(buffer.position() == 1024)
//get all the data, handle it
else
//hold buffer for next read
/**
* read in loop
*/
int target = 1024;
int totalRead = 0;
while(totalRead != 1024)
{
int readBytes = sc.read(intBuffer);
if(readBytes == -1)
break;
totalRead += readBytes;
}
//get all the data, handle it
相关文档:
作者 : 李志涛
邮箱地址 :lizhitao67116961@163.com
深圳优网科技有限公司
前几天看到有某位网友写了用http进行断点下载文件,但是网上没有看到ftp断点下载的文章或代码,现在本人写了一下。经过测试没有问题。请大家多多指教。如有疏漏的地方请各位技术友人指出。本人不胜感激。
package t ......
import java.text.*;
import java.util.*;
/**
*
* <p>
* Title: 通用工具类
* </p>
* <p>
* Description: 常用工具的集合,用来处理常见问题,比如中文乱码的方法等。
* </p>
* <p>
* Copyright: Copyright (c) 2003
* </p>
* <p>
* Company: Towery
* </ ......
<form name="UploadForm" enctype="multipart/form-data" method="post" action="upLoadImage.do">
<input type="file" name="File1" size="11" maxlength="20"/><input type="submit"value="上 传"/>
</form>
String path="images\\product\\";
String temp=thi ......
char在java中称为“字符型” 占2个字节
字符常量是用单引号括起的一个字符 且字符常量在内存中存储的是该字符在Unicode字符集中的排序位置,即整数
eg:char x='a'
内存x中存储的是字符a在Unicode字符集中的排序位置97 因此允许将上面的语句写成char x=97;
由此例可以得出以下结论:
1.要 ......
AWT中没有提供状态栏工具,可以在Frame中添加一个Panel实现类似的功能。基本功能有创建状态栏,添加指示器,移除指示器,改变指示器内容,获得指示器内容,添加指示器鼠标消息响应,添加指示器右键弹出菜单,获得对一个指示器的引用等。
import java.awt.Color;
import java.awt.Componen ......