Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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 ²¢·¢Ñ§Ï°


Ò»¡¢´´½¨ÈÎÎñ
 
ÈÎÎñ¿ÉÒÔÀí½âΪһ¶Î¶ÀÁ¢Ö´ÐеĴúÂ룬ËüÍê³ÉÒ»¶¨µÄ¹¦ÄÜ¡£
ÔÚJava 5¼°ÒÔÉÏ°æ±¾Öв»½ö¿ÉÒÔÀûÓà Runnable½Ó¿Ú£¬»¹¿ÉÒÔÀûÓÃCallable½Ó¿Ú¡£
    Á½ÖÖÈÎÎñµÄÇø±ð£ºRunnable µÄrun()·½·¨Íê³ÉµÄÈÎÎñÊÇûÓзµ»ØÖµµÄ - void
    ¶øCallable µÄcall()·½·¨Íê³ÉµÄÈÎÎñÊÇÓзµ»ØÖ ......

»¶Ó­Java±à³Ì°®ºÃÕß½»Á÷

     ´ó¼ÒºÃ!
     ÎÒÊÇÒ»¸ö±à³Ì°®ºÃÕß¡£
     ¾­¹ýרҵ¿ÎµÄѧϰ£¬ÓÐÒ»¶¨µÄ±à³Ì»ù´¡£¬¶ÔC/C++¡¢ASP.ENTÒÔ¼°Êý¾Ý¿â±È½ÏÊìϤ¡£
     ÏÖÔÚ£¬ÎÒÔÚÒ»¸öJavaÅàѵ°àѧϰ¡£
     ¿ÕÏÐÖ®Ó࣬ÔÚÕâÀïÕÒµ½ÁËÒ»¸ö½»Á÷µÄƽ̨£¬ ......

javaÖÐÊý¾ÝÀàÐͼäµÄÇ¿ÖÆת»»

javaÖлù±¾Êý¾ÝÀàÐÍ°´¾«¶ÈµÍ¸ßµÄÅÅÁÐ˳ÐòÊÇ
                        byte<short<int<long<float<double
1.µ±°Ñ¼¶±ðµÍµÄ±äÁ¿µÄÖµ¸³¸ø¼¶±ð¸ßµÄ±äÁ¿Ê±£¬ÏµÍ³»á×Ô¶¯Íê³ÉÊý¾ÝÀàÐ͵Äת»» ......

javaÓï¾ä

java´óÖÂÓÐ3ÖÖÓï¾ä£ºË³ÐòÓï¾ä¡¢Ìõ¼þÓï¾ä¡¢Ñ­»·Óï¾ä
Ìõ¼þÓï¾ä£º
      µÚÒ»ÖÖ£ºif Ìõ¼þ
                      Óï¾ä
      µÚ¶þÖÖ£ºif Ìõ¼þ
 &nbs ......

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ºÅ