Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

java nioÔÚ¶àÏ̻߳·¾³ÏµĶñÃÎÖ®ÖÕ½á

ÓÐÈË˵java nioÔÚ¶àÏ̻߳·¾³Ï±à³Ì¼òÖ±¾ÍÊǸö¶ñÃÎ,ÆäʵÄãÈç¹ûÄÜ°ÑÎÕסjava nio APIµÄÒªÁì,Äã¾Í¿ÉÒÔ½«Ö®¼ÝÔ¦.
0. Ò»¸ö channal ¶ÔÓ¦Ò»¸öSelectionKey in the same selector.
e.g:
SelectionKey sk=sc.register(selector, SelectionKey.OP_READ, handler);
sk==sc.register(selector, SelectionKey.OP_WRITE, handler) true?
selector.select() ÿ´Î·µ»ØµÄ¶ÔͬһchannalµÄskÊÇ·ñÏàͬ?
1.channel.register(...) may block if invoked concurrently with another registration[another.register(...)] or selection operation[selector.select(...)] involving *****the same selector*****.
Õâ¸öÊÇregister·½·¨jdk srcÉϵÄÔ­ÎÄ,
e.g:
Èç¹ûÒ»¸öselection threadÒѾ­ÔÚselect·½·¨Éϵȴýing,ÄÇôÕâ¸öʱºòÈç¹ûÓÐÁíÒ»ÌõÏ̵߳÷ÓÃchannal.register·½·¨µÄ»°,ÄÇôËü½«±»blocking.
2.selectionKey.cancel() : The key will be removed from all of the selector's key sets during *****the next selection operation[selector.select(...)]*****.
may block briefly if invoked concurrently with a cancellation[cancel()] or selection operation[select(...)] involving ***the same selector***.
Õâ¸öÒ²ÊÇcancel·½·¨jdk srcÉϵÄÔ­ÎÄ,
e.g:
ÄãÏȽ«Ò»¸öselectionKey.cancel(),È»ºóËæ¼´ÔÙchannel.register to the same selector,
ÔÚcancelºÍregisterÖ®¼ä,Èç¹ûûÓÐÏß³Ì(°üÀ¨µ±Ç°Ïß³Ì)½øÐÐselect²Ù×÷µÄ»°,
ÄÇô throws java.nio.channels.CancelledKeyException.
ËùÒÔ cancel-->select-->re-register. 
3.if don't remove the current selectedKey from selector.selectedKeys()[Set] ½«µ¼Ö selector.select(...) not block [may be cpu 100%,specially when client cut the current channel(connection)].
e.g:
Iterator<SelectionKey> it=selector.selectedKeys().iterator();
...for/while it.hasNext()...
it.remove();<------*****must do it. or Keys' Set.clear() finally;
if remove the current selectedKey from selector.selectedKeys()[Set] but don't sk.interestOps(sk.interestOps()& (~sk.readyOps()));½«µ¼Ö selector.select(...) not block [select() not block several times, or excepted exception]
4.op_write should not be registered to the selector. &nbs


Ïà¹ØÎĵµ£º

Java 6 ÖÐÒ²¿ÉÒÔÔËÐÐ javascript ච(ת)

¸ø Java SE ×¢Èë½Å±¾ÓïÑԵĻîÁ¦
Mustang µÄ½Å±¾ÓïÑÔÐÂÌØÐÔ

ÎĵµÑ¡Ïî

½«´ËÒ³×÷Ϊµç×ÓÓʼþ·¢ËÍ

½«´ËÒ³×÷Ϊµç×ÓÓʼþ·¢ËÍ



¼¶±ð£º Öм¶
Îâ 玥ò« (wuyuehao@cn.ibm.com), Èí¼þ¹¤³Ìʦ, IBM
2006 Äê 10 ÔÂ 30 ÈÕ
ÔÚ¼´½«·¢²¼µÄ Java SE6£¨Mustang£©ÖУ¬Ôö¼ÓÁ˶Խű¾ÓïÑÔµÄÖ§³Ö¡£Í¨¹ý¶Ô½Å± ......

³É¹¦Ç©Ï±¦ÐÅÈí¼þjavaÑз¢¹¤³Ìʦ

¾­¹ýÁËÒ»ÖܵÄŬÁ¦£¬³É¹¦Ç©ÏÂÁËÉϺ£±¦ÐÅÈí¼þÎ÷°²·Ö¹«Ë¾¡£
 
ÔÚÕâÀ¼òµ¥·ÖÏíÒ»ÏÂÕâ´ÎµÄ¾­Àú¡£
 
Ê×Ïȼòµ¥³ÂÊöϸöÈ˵ÄһЩ»ù±¾ÐÅÏ¢£¬Õý¹æͳÕб¾¿Æ·Ç¼ÆËã»úרҵ£¬2008-2009Äê8Ô½ÓÊܶ«·½±ê×¼Èí¼þ¹¤³ÌʦÅàѵ£¬Íê³ÉÁËһЩ±È½ÏÍêÕûµÄÏîÄ¿£¬ÕÆÎÕÁË»ù±¾µÄJ2EE¿ª·¢µÄºËÐļ¼Êõ¡£Åàѵ½áÊøÁË£¬²Î¼ÓÁËһЩ֪ÃûÆóÒµµÄУ԰ ......

ÉúƽµÚÒ»¶Î¹æ·¶Java´úÂë

ÏÂÃæÕâ¶Î´úÂëÊǾ­¹ý´úÂë·ÖÎö¹¤¾ßRational Software Analyser ·ÖÎö¹ýµÄ£¬¸Ã¹¤¾ß¹ØÓÚJavaµÄ¹æÔòÄ¿Ç°ÊÇ541Ìõ£¬ÊµÊô¿Á¿Ì¡£Ð´¶Î¹æ·¶µãµÄJava´úÂëÈÝÒ×ô£¡
/**
 *
 * @author zhp
 *
 * @version 1.0
 */
package com.rsar;
import java.util.Date;
/**
 *
 * @author zhp
  ......

Java°æµÄdatediff

¡¡¡¡MSSQLÖÐÌṩÁ˸ödatediffº¯ÊýÓÃÀ´¶ÔÁ½¸öʱ¼ä½øÐмõ·¨²Ù×÷£¬µ«ÔÚJavaÖÐȴûÓУ¬Èç¹ûÎÒÃÇÏëÖªµÀÁ½¸öÈÕÆÚ¼äÏà¸ôÁ˶àÉÙÌ죬»òÊÇÏà¸ôÁ˶àÉÙ¸öСʱÔòÒªÊÖ¹¤¼ÆËã¡£ÏÂÃæ´úÂëÄ£·ÂMSSQLµÄdatediffº¯ÊýÌṩÁËʹÓò»Í¬Ê±¼ä¼ä¸ôÀ´¼ÆËãÁ½¸öʱ¼äÏà²îµÄʱ¼ä¼ä¸ôµÄÊýÄ¿£¬±ÈÈçtimeIntervalΪdayÔò·µ»ØÏà²îµÄÌìÊý£¬ÎªmonthÔò·µ»ØÏà²îµÄÔÂÊý ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ