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
相关文档:
大家好!
我是一个编程爱好者。
经过专业课的学习,有一定的编程基础,对C/C++、ASP.ENT以及数据库比较熟悉。
现在,我在一个Java培训班学习。
空闲之余,在这里找到了一个交流的平台, ......
<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 ......
java的基本数据类型以及长度如下:
1.整数型
字节型byte:占1个字节 范围为 -28-1至28-1-1
短整型short:占2个字节 范围为 -22*8-1 至 22*8-1-1
& ......
char在java中称为“字符型” 占2个字节
字符常量是用单引号括起的一个字符 且字符常量在内存中存储的是该字符在Unicode字符集中的排序位置,即整数
eg:char x='a'
内存x中存储的是字符a在Unicode字符集中的排序位置97 因此允许将上面的语句写成char x=97;
由此例可以得出以下结论:
1.要 ......
注:不适合web工程
1、利用System.getProperty()函数获取当前路径:
System.out.println(System.getProperty("user.dir"));//user.dir指定了当前的路径
2、使用File提供的函数获取当前路径:
File directory = new File("");//设定为当前文件夹
try{
System.out.println(directory. ......