易截截图软件、单文件、免安装、纯绿色、仅160KB

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



相关文档:

Java常用工具类


import java.text.*;
import java.util.*;
/**
*
* <p>
* Title: 通用工具类
* </p>
* <p>
* Description: 常用工具的集合,用来处理常见问题,比如中文乱码的方法等。
* </p>
* <p>
* Copyright: Copyright (c) 2003
* </p>
* <p>
* Company: Towery
* </ ......

Java 6 RowSet 使用完全剖析(2)

Java 6 RowSet 使用完全剖析(2)
关键字: rowset
分页
由于 CachedRowSet 是将数据临时存储在内存中,因此对于许多 SQL 查询,会返回大量的数据。如果将整个结果集全部存储在内存中会占用大量的内存,有时甚至是不可行的。对此 CachedRowSet 提供了分批从 ResultSet 中获取数据的方式,这就是分页。应用程序可以简单的通 ......

JAVA缓存

JAVA缓存有两种:
一、文件缓存,是指把数据存储在磁盘上,可以XML格式,也可以序列化文件DAT格式还是其它文件格式。
二、内存缓存,也就是实现一个类中静态Map,对这个Map进行常规的增删查。
其代码如下:
目录 [隐藏]
1 Cache类
2 CacheManager类
 JAVA缓存-Cache类      &n ......

Java 的缓存的实质

计算机缓存的定义 :缓存是CPU的一部分,它存在于CPU中
就此可以说明 CPU中不可能存放大量的数据
所以java 的缓存 不是真正意义上的缓存
而且
缓存是为了解决CPU速度和内存速度的速度差异问题
内存中被CPU访问最频繁的数据和指令被复制入CPU中的缓存,这样CPU就可以不经常到象“蜗牛”一样慢的内存中去取数 ......

Java用AWT实现的状态栏

      AWT中没有提供状态栏工具,可以在Frame中添加一个Panel实现类似的功能。基本功能有创建状态栏,添加指示器,移除指示器,改变指示器内容,获得指示器内容,添加指示器鼠标消息响应,添加指示器右键弹出菜单,获得对一个指示器的引用等。
import java.awt.Color;
import java.awt.Componen ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号