ʹÓÃJava NIO±àд¸ßÐÔÄܵķþÎñÆ÷
תÔصØÖ·£ºhttp://www.javaeye.com/topic/40489
´ÓJDK 1.4¿ªÊ¼£¬JavaµÄ±ê×¼¿âÖоͰüº¬ÁËNIO£¬¼´ËùνµÄ“New IO”¡£ÆäÖÐ×îÖØÒªµÄ¹¦ÄܾÍÊÇÌṩÁË“·Ç×èÈû”µÄIO£¬µ±È»°üÀ¨ÁËSocket¡£NonBlockingµÄIO¾ÍÊǶÔselect(Unixƽ̨ÏÂ)ÒÔ¼° WaitForMultipleObjects(Windowsƽ̨)µÄ·â×°£¬ÌṩÁ˸ßÐÔÄÜ¡¢Ò×ÉìËõµÄ·þÎñ¼Ü¹¹¡£
˵À´²ÑÀ¢£¬Ö±µ½JDK1.4²ÅÓÐÕâÖÖ¹¦ÄÜ£¬µ«³Ùµ½Õß²»Ò»¶¨Ã»ÓÐó¦Ð·³Ô£¬NIO¾ÍÌṩÁËÓÅÐãµÄÃæÏò¶ÔÏóµÄ½â¾ö·½°¸£¬¿ÉÒԺܷ½±ãµØ±àд¸ßÐÔÄܵķþÎñÆ÷¡£
»°Ëµ»ØÀ´£¬´«Í³µÄServer/ClientʵÏÖÊÇ»ùÓÚThread per request£¬¼´·þÎñÆ÷Ϊÿ¸ö¿Í»§¶ËÇëÇó½¨Á¢Ò»¸öÏ̴߳¦Àí£¬µ¥¶À¸ºÔð´¦ÀíÒ»¸ö¿Í»§µÄÇëÇó¡£±ÈÈçÏñTomcat£¨Ð°汾Ҳ»áÌṩNIO·½°¸£©¡¢ResinµÈWeb·þÎñÆ÷¾ÍÊÇÕâÑùʵÏֵġ£µ±È»ÎªÁ˼õÉÙ˲¼ä·åÖµÎÊÌ⣬·þÎñÆ÷Ò»°ã¶¼Ê¹ÓÃÏ̳߳أ¬¹æ¶¨ÁËͬʱ²¢·¢µÄ×î´óÊýÁ¿£¬±ÜÃâÁËÏ̵߳ÄÎÞÏÞÔö³¤¡£
µ«ÕâÑùÓÐÒ»¸öÎÊÌ⣺Èç¹ûÏ̳߳صĴóСΪ100£¬µ±ÓÐ100¸öÓû§Í¬Ê±Í¨¹ýHTTPÏÖÔÚÒ»¸ö´óÎļþʱ£¬·þÎñÆ÷µÄÏ̳߳ػáÓÃÍ꣬ÒòΪËùÓеÄÏ̶߳¼ÔÚ´«Êä´óÎļþÁË£¬¼´Ê¹µÚ101¸öÇëÇóÕß½ö½öÇëÇóÒ»¸öÖ»ÓÐ10×Ö½ÚµÄÒ³Ã棬·þÎñÆ÷Ò²ÎÞ·¨ÏìÓ¦ÁË£¬Ö»Óеȵ½Ï̳߳ØÖÐÓпÕÏеÄÏ̳߳öÏÖ¡£
ÁíÍ⣬Ï̵߳ĿªÏúÒ²ÊǺܴóµÄ£¬ÌرðÊÇ´ïµ½ÁËÒ»¸öÁÙ½çÖµºó£¬ÐÔÄÜ»áÏÔÖøϽµ£¬ÕâÒ²ÏÞÖÆÁË´«Í³µÄSocket·½°¸ÎÞ·¨Ó¦¶Ô²¢·¢Á¿´óµÄ³¡ºÏ£¬¶ø“·Ç×èÈû”µÄIO¾ÍÄÜÇáËɽâ¾öÕâ¸öÎÊÌâ¡£
ÏÂÃæÖ»ÊÇÒ»¸ö¼òµ¥µÄÀý×Ó£º·þÎñÆ÷ÌṩÁËÏÂÔØ´óÐÍÎļþµÄ¹¦ÄÜ£¬¿Í»§¶ËÁ¬½ÓÉÏ·þÎñÆ÷µÄ12345¶Ë¿Úºó£¬¾Í¿ÉÒÔ¶ÁÈ¡·þÎñÆ÷·¢Ë͵ÄÎļþÄÚÈÝÐÅÏ¢ÁË¡£×¢ÒâÕâÀïµÄ·þÎñÆ÷Ö»ÓÐÒ»¸öÖ÷Ị̈߳¬Ã»ÓÐÆäËûÈκÎÅÉÉúỊ̈߳¬ÈÃÎÒÃÇ¿´¿´NIOÊÇÈçºÎÓÃÒ»¸öÏ̴߳¦ÀíN¸öÇëÇóµÄ¡£
NIO·þÎñÆ÷×îºËÐĵÄÒ»µã¾ÍÊÇ·´Ó¦Æ÷ģʽ£ºµ±ÓиÐÐËȤµÄʼþ·¢ÉúµÄ£¬¾Í֪ͨ¶ÔÓ¦µÄʼþ´¦ÀíÆ÷È¥´¦ÀíÕâ¸öʼþ£¬Èç¹ûûÓУ¬Ôò²»´¦Àí¡£ËùÒÔʹÓÃÒ»¸öÏß³Ì×öÂÖѯ¾Í¿ÉÒÔÁË¡£µ±È»ÕâÀïÕâÊǸöÀý×Ó£¬Èç¹ûÒª»ñµÃ¸ü¸ßÐÔÄÜ£¬¿ÉÒÔʹÓÃÉÙÁ¿µÄỊ̈߳¬Ò»¸ö¸ºÔð½ÓÊÕÇëÇó£¬ÆäËûµÄ¸ºÔð´¦ÀíÇëÇó£¬ÌرðÊǶÔÓÚ¶àCPUʱЧÂÊ»á¸ü¸ß¡£
¹ØÓÚʹÓÃNIO¹ý³ÌÖгöÏÖµÄÎÊÌ⣬×îΪÆÕ±éµÄ¾ÍÊÇΪʲôûÓÐÇëÇóʱCPUµÄÕ¼ÓÃÂÊΪ100%£¿³öÏÖÕâÖÖÎÊÌâµÄÖ÷ÒªÔÒòÊÇ×¢²áÁ˲»¸ÐÐËȤµÄʼþ£¬±ÈÈçÈç¹ûûÓÐÊý¾ÝÒª·¢µ½¿Í»§¶Ë£¬¶øÓÖ×¢²áÁËдʼþ£¨OP_WRITE£©£¬ÔòÔÚ Selector.select()ÉϾͻáʼÖÕÓÐʼþ³öÏÖ£¬CPU¾ÍÒ»Ö±´¦ÀíÁË£¬¶ø´Ëʱselect()Ó¦¸ÃÊÇ×èÈûµÄ¡£
ÁíÍâÒ»¸öÖµµÃ×¢ÒâµÄÎÊÌâÊÇ£ºÓÉÓÚֻʹÓÃÁËÒ»¸öỊ̈߳¨¶à¸öÏß³ÌÒ²Èç´Ë£©´¦À
Ïà¹ØÎĵµ£º
×î½ü¹«Ë¾Åöµ½ÐèÒªÓÃͼ±íµÄÐÎʽÏÔʾһЩÊý¾Ý£¬ÎҾͿªÊ¼µ½ÍøÉϲéѯ£¬²éµ½ÁËjfreechartºÍamcharts,ÕâÁ½ÕßÎÒ¶¼ÊµÏÖ¹ýÁË£¬jfreechart×îºóÉú³ÉͼƬ£¬µ«ÊÇͼƬЧ¹û²»ÊÇÎÒÏëÒªµÄ£¬È»ºóÓÖÑо¿amcharts ËüµÄЧ¹ûȷʵºÜºÃ£¬¶øÇÒ¹Ù·½ÍøÕ¾ÉÏ»¹ÓкÃЩÀý×ӿɹ©ÏÂÔØ£¬ÍøÖ·ÊÇ:www.amcharts.com
£¨ÏëÒªÍê³ÉÒ»¸öamchartsͼÐÎÐèÒªswfobjects. ......
Ò»¡¢PO:
persistant object
³Ö¾Ã¶ÔÏó,¿ÉÒÔ¿´³ÉÊÇÓëÊý¾Ý¿âÖеıíÏàÓ³ÉäµÄjava¶ÔÏó¡£×î¼òµ¥µÄPO¾ÍÊǶÔÓ¦Êý¾Ý¿âÖÐij¸ö±íÖеÄÒ»Ìõ¼Ç¼£¬¶à¸ö¼Ç¼¿ÉÒÔÓÃPOµÄ¼¯ºÏ¡£POÖÐÓ¦¸Ã²»°ü
º¬ÈκζÔÊý¾Ý¿âµÄ²Ù×÷¡£
¶þ¡¢VO
:value
objectÖµ¶ÔÏó¡£Í¨³£ÓÃÓÚÒµÎñ²ãÖ®¼äµÄÊý¾Ý´«µÝ£¬ºÍPOÒ»ÑùÒ²Êǽö½ö°üº¬Êý¾ ......
¡¡¡¡XJad2.2£¨JavaÔ´´úÂë·´±àÒ빤¾ß£©
¡¡¡¡Á¢¼´ÏÂÔØ
¡¡¡¡XJadÊÇ»ùÓÚJadºËÐĵÄJavaÔ´³ÌÐò·´±àÒëÈí¼þ£¬ÄÚÖÃJad1.5.8e2¡£
¡¡¡¡XJad¿É´¦Àí¶à¸ö*.classÎļþ£¬¿ÉÒÔ´¦ÀíÎļþ¼ÐÄÚµÄËùÓÐÎļþ£¬ÉõÖÁ¿ÉÒÔ´¦Àí*.jarÎļþ¡£
¡¡¡¡XJad´øÓжàÒ³ÃæÎı¾±à¼Æ÷£¬·´±àÒëÍê³Éºó¿ÉÒÔÖ±½Ó±à¼²é¿´£¬±à¼Æ÷Ö§³ÖjavaÓï·¨µÄ¸ßÁÁÏÔʾ¹¦ÄÜ¡£
¡¡¡¡ ......
InputStream stream;
Properties prop = new Properties();// ÊôÐÔ¼¯ºÏ¶ÔÏó
stream = getClass().getResourceAsStream("NcJdbc.properties");
prop.load(stream);
stream.close();// ¹Ø±ÕÁ÷
String databaseName=prop.getProperty("jdbc.databaseName");
InputStream stream;
Properties prop = new Properties(); ......
typedef struct
{
BYTE baOrigMDN[8]; /* Ö÷½ÐÓû§MDN */
BYTE baDestMDN[8]; /* ±»½ÐÓû§MDN */
BYTE bOrigIsVIP;   ......