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
test.d ......
Java:
Simple HTTPUrlConnection example
package
ChinaCache;
import
java.io.BufferedReader;
import
java.io.IOException;
import
java.io.InputStreamReader;
import
java.io.OutputStreamWriter;
import
java.net.HttpURLConnection;
import
java.net.MalformedURLEx ......
ÿÌì»ù´¡£¨1£©£¬´®Æ¥ÅäÖ®Brute-ForceËã·¨£¬×î¼òµ¥µÄ±éÀúËã·¨¡£ÁíÍâÓÐKMPËã·¨£¬ÊǶԴËËã·¨µÄ¸Ä½ø£¬±ÜÃâÿ´Î±È½Ï¶¼»Ø»ØÍË¡£
package ibees.sample;
/**
* ×Ö·û´®Æ¥ÅäģʽËã·¨Brute-ForceËã·¨£¬´ËË㷨ÿ´Î±È½Ï¶¼»á»ØÍË
* @author hhzxj2008
* */
public class StringMatch {
/**
* Ï൱ÓÚjava.lang.StringµÄi ......
×öB/SµÄÆóÒµ¼¶Ó¦Ó㬿ÉÄÜ»áÓöµ½ÕâÑùÒ»ÖÖÇé¿ö£¬¿Í»§µÄÎĵµ£¨wordµÈ£©±£´æÔÚÒ»¸öĿ¼Ï£¬ÐèҪͨ¹ýµÇ¼²ÅÄÜ¿´µ½£¬µ«ÊÇ
ÕâЩÓÖ¶¼ÊǾ²Ì¬µØÖ·£¬ËùÒÔÄÜÖ±½ÓÊäÈëµØÖ·¾Í¿ÉÒÔ·ÃÎʵ½Îĵµ¡£Õâʱ¾ÍÐèÒªÓõ½Filter¹ýÂËÆ÷ÁË¡£
Servlet
APIµÄ2.3°æ±¾µÄÒ»¸öй¦ÄܾÍÊÇÄܹ»ÎªservletºÍJSPÒ³Ãæ¶¨Òå¹ýÂËÆ÷¡£¹ýÂËÆ÷ÌṩÁËijЩÔçÆÚ·þÎñÆ÷Ë ......
½«FlexÓëSpring¼¯³Éºó£¨BlazeDS ÓëSpring¼¯³ÉÖ¸ÄÏ £©£¬µÚÒ»¸öÃæÁÙµÄÎÊÌâ¾ÍÊÇ£º¶ÔÓÚJava¶Ë·µ»ØµÄ¸÷ÖÖJavaÀàÐ͵ĶÔÏó£¬FlexÖÐÄÜ·ñÓÐÏàÓ¦µÄÊý¾ÝÀàÐÍÀ´Ó³Éä¡£
´¦Àí£¬ÓÈÆäÊÇList¡¢Set¡¢Map¼°POJO¶ÔÏóÖµ¡£
ÔÚ BlazeDS ÓëSpring¼¯³ÉÖ¸ÄÏ Àý×ӵĻù´¡ÉÏ£¬µ÷ÕûÏà¹ØµÄ²âÊÔ´úÂëÈçÏ£º
1¡¢Java¶Ë
1.1¡¢com.yeeach.HelloWorldService ......