易截截图软件、单文件、免安装、纯绿色、仅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编写多线程ftp断点下载文件程序

作者 : 李志涛
邮箱地址 :lizhitao67116961@163.com
深圳优网科技有限公司
 
前几天看到有某位网友写了用http进行断点下载文件,但是网上没有看到ftp断点下载的文章或代码,现在本人写了一下。经过测试没有问题。请大家多多指教。如有疏漏的地方请各位技术友人指出。本人不胜感激。
 
 
package t ......

Java EE 6 Platform草案包含了Web Profile


Java EE 6 Platform草案包含了Web Profile
来源:http://www.infoq.com/cn/news/2009/02/java-ee6-draft
作者 Dionysios G. Synodinos 译者 宋玮 发布于 2009年2月3日 下午10时55分
社区 Java 主题 Enterprise Application Blocks 标签 Java EE
Java EE 6 Platform规范 ......

java中数据类型间的强制转换

java中基本数据类型按精度低高的排列顺序是
                        byte<short<int<long<float<double
1.当把级别低的变量的值赋给级别高的变量时,系统会自动完成数据类型的转换 ......

Oracle + Sun: Java Strategy

Oracle and Sun
http://www.oracle.com/events/productstrategy/index.html
Oracle + Sun: Java Strategy
   http://oracle.com.edgesuite.net/ivt/4000/8104/9236/12630/lobby_external_flash_clean_480x360/default.htm 
Oracle + Sun: Java Strategy
  ......

JAVA获取当前工程路径(非web工程)


 
注:不适合web工程
1、利用System.getProperty()函数获取当前路径:
System.out.println(System.getProperty("user.dir"));//user.dir指定了当前的路径
2、使用File提供的函数获取当前路径:
File directory = new File("");//设定为当前文件夹
try{
    System.out.println(directory. ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号