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
相关文档:
import java.text.*;
import java.util.*;
/**
*
* <p>
* Title: 通用工具类
* </p>
* <p>
* Description: 常用工具的集合,用来处理常见问题,比如中文乱码的方法等。
* </p>
* <p>
* Copyright: Copyright (c) 2003
* </p>
* <p>
* Company: Towery
* </ ......
大家好!
我是一个编程爱好者。
经过专业课的学习,有一定的编程基础,对C/C++、ASP.ENT以及数据库比较熟悉。
现在,我在一个Java培训班学习。
空闲之余,在这里找到了一个交流的平台, ......
Java 6 RowSet 使用完全剖析(1)
关键字: rowset
javax.sql.rowset 自 JDK 1.4 引入,从 JDK 5.0 开始提供了参考实现。它主要包括 CachedRowSet,WebRowSet,FilteredRowSet,JoinRowSet 和 JdbcRowSet。 除了 JdbcRowSet 依然保持着与数据源的连接之外,其余四个都是 Disconnected RowSet。
相比较 java.sql.ResultSet ......
char在java中称为“字符型” 占2个字节
字符常量是用单引号括起的一个字符 且字符常量在内存中存储的是该字符在Unicode字符集中的排序位置,即整数
eg:char x='a'
内存x中存储的是字符a在Unicode字符集中的排序位置97 因此允许将上面的语句写成char x=97;
由此例可以得出以下结论:
1.要 ......
每天基础(1),串匹配之Brute-Force算法,最简单的遍历算法。另外有KMP算法,是对此算法的改进,避免每次比较都回回退。
package ibees.sample;
/**
* 字符串匹配模式算法Brute-Force算法,此算法每次比较都会回退
* @author hhzxj2008
* */
public class StringMatch {
/**
* 相当于java.lang.String的i ......